canjs / can-stache

Live binding handlebars templates
https://canjs.com/doc/can-stache.html
MIT License
10 stars 13 forks source link

Make dev.warn tests resilient to new warnings #302

Closed phillipskevin closed 6 years ago

phillipskevin commented 7 years ago

We have many tests that assert the value of a warning message. When other can-* repos add new warnings, these tests often break. We should use a flag to only assert the value of warning messages when we're making the stache(...) call we're trying to test. We should be able to do this with a simple flag:

var checkWarnings = false;
canDev.warn = function(text) {
    if (checkWarnings){ 
        equal(text, texts[count++]);
    }
};

...

checkWarnings = true;
stache(...);

...
phillipskevin commented 7 years ago

Another option (given by @christopherjbaker via @imaustink) is to only assert if the warning matches the expected value along with expect(...) to make sure the correct number of warnings are given like this test.

christopherjbaker commented 7 years ago

I think the best option would be a built in mechanism, something like canDev.mockWarn('expected warning') or canDev.mockWarn([ 'expected warning', 'other warning' ]). Besides simplifying the tests instead of having that code every time, it would also make future changes to this logic simpler. =]

phillipskevin commented 7 years ago

We may want to create a can-test-helpers module for useful functions like this.