Last active
June 29, 2018 19:34
-
-
Save simon2k/d1fb6e887be7de2ba2bddc79a90f7ccc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// under-test.ts | |
import { myFunc } from './service'; | |
export class UnderTest { | |
display() { | |
const val = myFunc('abc'); | |
console.log('display'); | |
return val; | |
} | |
} | |
// service.ts | |
export const myFunc = (value) => { | |
console.log('#myFunc value: ', value); | |
return 'val from myFunc'; | |
}; | |
// undert-test.spec.ts | |
import { UnderTest } from './under-test'; | |
import * as service from './service'; | |
describe('UnderTest', () => { | |
describe('#display', () => { | |
it('returns value from my func', () => { | |
spyOn(service, 'myFunc').and.returnValue('my-value'); | |
const obj = new UnderTest(); | |
expect(obj.display()).toEqual('my-value'); | |
}); | |
it('calls my func', () => { | |
spyOn(service, 'myFunc').and.returnValue('my-value'); | |
const obj = new UnderTest(); | |
obj.display(); | |
expect(service.myFunc).toHaveBeenCalledWith('abc'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment