I am trying to write some tests covering a Class I have written that can have multiple, varying components. What I am trying to do is create a new class instance and save it to a variable then test if that variable has a specific key.
describe('Year Indicator', () => {
it('should return a Watch instance with a "year" property.', () => {
const settings = {
testing: true,
dials: [{
hands: {
hour: 'hour-hand',
minute: 'minute-hand',
second: 'second-hand',
}
}],
year: {
id: 'year-hand'
}
};
const test = new Watch(settings);
assert.deepEqual(test, { year: { id: 'year-hand' } });
});
});
In this example, I expect test
to return a new instance of Watch which contains the properties from settings
. However, whenever I run this test, it errors because test
returns as an empty object.
1) Year Indicator
should return a Watch instance with a "year" property.:
AssertionError [ERR_ASSERTION]: Watch {} deepEqual { year: { id: 'year-hand' } }
+ expected - actual
-{}
+{
+ "year": {
+ "id": "year-hand"
+ }
+}
The only thing I can really think of is the initial Watch class does make a call using Moment to get the current date. Is it possible that I need to delay this test until the full object is returned?
I am running all of my tests through the terminal using Mocha and Chai assert.
Aucun commentaire:
Enregistrer un commentaire