재스민 치트 시트

13760 단어 jasminecheatsheet

참고문헌


  • Jest cheatsheet도 참조하십시오. Jest는 Jasmine을 사용하므로 유사한 API를 가지고 있습니다.
  • https://jasmine.github.io
  • Jasmine Cheat Sheet

  • [테스트] 이벤트 스파이




    spyOnEvent($('#some_element'), 'click')
    $('#some_element').click()
    expect('click').toHaveBeenPreventedOn($('#some_element'))
    expect('click').toHaveBeenTriggeredOn($('#some_element'))
    


    [테스트] HTML 러너




    var jasmineEnv = jasmine.getEnv()
    jasmineEnv.updateInterval = 250
    
    var htmlReporter = new jasmine.HtmlReporter()
    jasmineEnv.addReporter(htmlReporter)
    
    $(function() { jasmineEnv.execute() })
    


    재스민 jQuery



    [테스트] 비동기




    test('works with promises', () => {
      return new Promise((resolve, reject) => {
        ···
      })
    })
    


    테스트가 약속을 반환하도록 하십시오.

    [테스트] 스파이 생성




    stub = jasmine.createSpy('stub')
    stub('hello')
    



    expect(stub.identity).toEqual('stub')
    expect(stub).toHaveBeenCalled()
    


    [테스트] 스파이




    spyOn(foo, 'setBar')
    spyOn(foo, 'setBar').andReturn(123)
    spyOn(foo, 'getBar').andCallFake(function() { return 1001; })
    foo.setBar(123)
    



    expect(foo.setBar).toHaveBeenCalled()
    expect(foo.setBar).toHaveBeenCalledWith(123)
    expect(foo.setBar.calls.length).toEqual(2)
    expect(foo.setBar.calls[0].args[0]).toEqual(123)
    


    [테스트] 보류 중




    xit('this is a pending test', () => {
      ···
    })
    



    xdescribe('this is a pending block', () => {
      ···
    })
    


    [테스트] 후크




    beforeEach(() => {
      ···
    })
    



    afterEach(() => {
      ···
    })
    


    [테스트] 기대




    expect(true).toBe(true)
    expect(true).not.toBe(true)
    



    expect(a).toEqual(bar)
    



    expect(message).toMatch(/bar/)
    expect(message).toMatch('bar')
    



    expect(a.foo).toBeDefined()
    expect(a.foo).toBeUndefined()
    expect(a.foo).toBeNull()
    



    expect(a.foo).toBeTruthy()
    expect(a.foo).toBeFalsy()
    



    expect(message).toContain('hello')
    



    expect(pi).toBeGreaterThan(3)
    expect(pi).toBeLessThan(4)
    expect(pi).toBeCloseTo(3.1415, 0.1)
    



    expect(func).toThrow()
    


    [테스트] 테스트 작성




    describe('A suite', () => {
      it('works', () => {
        expect(true).toBe(true)
      })
    })
    

    좋은 웹페이지 즐겨찾기