jasmine - sinon mock typescript class -


i'm trying test typescript class that's used in one.

suppose i've got api like:

class api {   foo() {     return 40 + 2;   } } 

and i've got consumer:

class consumer {   constructor(api: api) {   }    bar() {     console.log(this.api.foo());   } } 

now, want validate api.foo called when consumer.bar called.

so i've got following jasmine spec:

describe('consumer', () => {   let mockapi;    beforeeach(() => {     mockapi = sinon.mock(new api());   });    it('should call foo when calling bar', () => {     const sut = new consumer(mockapi);      mockapi.expect('foo').once.return(666);      sut.bar();      mockapi.validate();   }); }); 

this test fails though giving following error message:

typeerror: undefined not constructor (evaluating 'mockapi.expect('foo')')

any ideas i'm doing wrong?


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -