You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the subject under test and/or the arg passed to the contains() matcher was created using IIFE then the matcher is not working correctly.
Here is an example:
it('TD contains with IIFE objects',()=>{varbrew=td.function();varContainer=(function(){functionContainer(){}returnContainer;}());varCoffee=(function(){functionCoffee(){this.container=newContainer();}returnCoffee;}());varsmallCoffeeContainer=newCoffee();smallCoffeeContainer.container.size='S';varlargeCoffeeContainer=newCoffee();largeCoffeeContainer.container.size='L';varsmallCupOfCoffee=newCoffee();smallCupOfCoffee.container.size='S';smallCupOfCoffee.container.type='cup';smallCupOfCoffee.ingredient='beans';console.log('smallCupOfCoffee',JSON.stringify(smallCupOfCoffee));console.log('smallCoffeeContainer',JSON.stringify(smallCoffeeContainer));console.log('largeCoffeeContainer',JSON.stringify(largeCoffeeContainer));td.when(brew(td.matchers.anything())).thenReturn('little steam');expect(brew(smallCupOfCoffee)).to.equal('little steam');td.verify(brew(td.matchers.contains(smallCoffeeContainer)));});
This produces:
Error: Unsatisfied verification on test double.
Wanted:
- called with `(contains("[object Object]"))`.
But was actually called:
- called with `("[object Object]")`.
at Object.fail (node_modules\testdouble\lib\log.js:21:13)
at Object.module.exports [as verify] (node_modules\testdouble\lib\verify.js:28:20)
at Context.<anonymous> (build\test\controllers\services-controller.tests.js:182:20)
This is a fairly long example and what was going on didn't immediately jump out to me. (Given what I remember of using IIFEs, the issue is probably the result of somebody comparing something by reference, but that reference changing if the IIFE is re-invoked)
I threw triage of this issue on the backlog, but would encourage you to attempt to debug the root problem on your own if you need a quick resolution
If the subject under test and/or the arg passed to the contains() matcher was created using IIFE then the matcher is not working correctly.
Here is an example:
This produces:
The three console.log lines produced:
If I refactor the test to use objects which have been created declaratively:
In this case it just works. The console logs print the same.
I can make the IIFE case work by stripping the functions out of the objects before invoking the tests:
... but that doesn't help me when the subject under test is creating the IIFE.
The text was updated successfully, but these errors were encountered: