Hi everyone,
I'm new to qUnit, so I might have missed something. I'm currently writing some tests and misses the possibility to test against regular expression.
For example, in one of my tests, I'm using a call to 'css' and then checking the 'style' attribute to ensure the value has been correctly updated.
The main problem is that I get "width: 50%; margin-top: 15px; background-color: rgb(21, 72, 38); " on Safari and "width: 50%; margin-top: 15px; background-color: rgb(21, 72, 38);" on Firefox. The result is the same except an extra-space at the end on Safari.
I could do something like this of course:
- ok(/^width: 50%; margin-top: 15px; background-color: rgb\(21, 72, 38\); ?/.test(myvalue), 'The style attribute has been updated')
But I really like the fact that 'equal' displays the expected and obtained values in the test results.
What I wrote is this:
- function match(res, exp, msg) {
- if (exp.test(res)) {
- equal('Match with: ' + exp,
- 'Match with: ' + exp,
- msg);
- } else {
- equal(res,
- 'Expected match with: ' + exp,
- msg);
- }
- }
and in my test:
- match(myvalue,
- /^width: 50%; margin-top: 15px; background-color: rgb\(21, 72, 38\); ?/,
- 'The style attribute has been updated')
Ok, that's pretty simple and ugly* but it gives my the possibility to test a value against a regular expression. And if the test fails, I can quickly see the problem in the overview.
Do you think this kind of system (at least a less ugly verson :D ) could be integrated in the future ? Or did I miss something that natively allows testing against regexp ?
Regards,
Vincent
* there is the possibility that 'res' and "'Expected match with: ' + exp" give the same result, which would give a positive result to a failing test, so it needs improvements. In my case the problem does not arive as I'm testing against attributes of nodes.
But I am aware of this flaw ;)