Incomplete tests/setups/teardowns with RequireJS
- Vorherrschende Sprache
- JavaScript
- Sterne
- 1.9k
- Forks
- 359
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Here is my test (using grunt-contrib-nodeunit):
```
var requirejs = require('requirejs');
exports.test = function(test){
test.expect(1);
requirejs(['dist/test-hts'],function(obj){
test.ok(true, 'hello');
test.done();
});
};
```
For some reason, this doesn't work! It appears as though RequireJS doesn't play nice with node unit. I've been trying to get testing working for the better part of 3 days with no luck so far, even on the most simple of tests like above!
This happens when I run with vanilla nodeunit from the command line:
```
test.js
FAILURES: Undone tests (or their setups/teardowns):
- test
To fix this, make sure all tests call test.done()
```
If I move the `.done()` to the outside of the callback, it just skips the test all together and says that it expected 1 assertion but found none.
I have also tried it this way:
```
var requirejs = require('requirejs');
requirejs.config({
nodeRequire: require,
baseUrl: __dirname
});
requirejs(['../dist/test-hts'],function(obj){
console.log('loaded...');
exports.test = function(test){
test.expect(1);
test.ok(true, 'hello');
test.done();
};
});
```
It results in:
```
OK: 0 assertions (41ms)
```
Also, if I run this same file using node rather than nodeunit (just to check execution), I get the following output:
```
loaded...
```
So I know that the module is loading properly, just not with nodeunit!
Any help here would be great. I don't understand why nodeunit wouldn't work with such a well-known AMD tool like RequireJS. Thanks!
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginne damit, die bereitgestellte test.js mit vanilla nodeunit und dem grunt-contrib-nodeunit-Setup zu reproduzieren. Verfolge, wie nodeunit den Test entdeckt und test.done() behandelt, während der RequireJS-Callback dist/test-hts lädt. Als erledigt gilt die Aufgabe, wenn das Beispiel ohne einen Fehler wegen eines nicht abgeschlossenen Tests durchläuft und die erwartete Assertion erfasst.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- testing-qa
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100