I'm trying to apply a Jasmine test to my JS program (just a game) and it doesn't create new instances for some reason. Maybe some of you can help me find the error.
'use strict';
describe('logic(bingo)',function() {
var bin
beforeEach(function() {
bin = new Bingo('Alex')
})
it('should throw error if name is not a string',function() {
bin=new Bingo()
expect(function() {
return bin.name
}).toThrowError('Input a string name')
})
it('should board.length===3 and board[0].length===5',function() {
expect(bin.board.length).toBe(3)
expect(bin.board[0].length).toBe(5)
})
}
bin doesn't store a "new Bingo". It keeps being undefined. This class Bingo is declared in a different file, the links are correct.
Thanks in advance.
how are you throwing an error when name is not supplied or is not a string?
i think it should be in constructor and something like:
...
if(!name || typeof name !== 'string') {
throw new Error('Input a string name');
}
...
and also checking for it throws on instantiation not on getter:
it('should throw error if name is not a string',function() {
expect(function() {
new Bingo(1)
}).toThrowError('Input a string name')
})
here is a working plunk http://plnkr.co/edit/Z4wT9s
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.