재스민 치트 시트
13760 단어 jasminecheatsheet
참고문헌
[테스트] 이벤트 스파이
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)
})
})
Reference
이 문제에 관하여(재스민 치트 시트), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/hoanganhlam/jasmine-cheat-sheet-4gfh텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)