Skip to content

Instantly share code, notes, and snippets.

@simon2k
Last active June 29, 2018 19:34
Show Gist options
  • Save simon2k/d1fb6e887be7de2ba2bddc79a90f7ccc to your computer and use it in GitHub Desktop.
Save simon2k/d1fb6e887be7de2ba2bddc79a90f7ccc to your computer and use it in GitHub Desktop.
// 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