Closed ckpiggy closed 6 years ago
@ckpiggy you can use multiple times OK()
or FAIL()
but not in another callback
. This is correct.
TEST('long run 1', function () {
OK(true, 'long run 1');
});
TEST('long run 2', function () {
OK(true, 'long run 2');
});
// etc..
TEST('next', function () {
OK(true, 'the next test')
})
In other word: OK()
and FAIL()
ends the current test. It's something similar to your finished
example. Solution:
TEST('long run', function () {
setTimeout(function () {
OK(true, 'long run 0')
OK(true, 'long run 1')
OK(true, 'long run 2')
OK(true, 'long run 3')
OK(true, 'long run 4')
OK(true, 'long run 5')
}, 100)
});
@petersirka I think the document should update, it looks like we could have multiple OK
in a test.
Yes, but in a row ... But I'll add not in some callback.
@petersirka I think I got your point now.
The OK
and FAIL
should be called synchronized.
My test look like this
TEST('get service', 'some/url',async function (builder) {
builder.get().exec(async (err, data, resp) => {
OK(resp.status === 200, 'status')
try {
const dbData = await fetchDbData()
OK(dbData === mockedData, 'check db')
}
})
})
And the problem happened in second OK
check
So I can simply modify my test to
TEST('get service', 'some/url',async function (builder) {
builder.get().exec(async (err, data, resp) => {
try {
const dbData = await fetchDbData()
OK(resp.status === 200, 'status')
OK(dbData === mockedData, 'check db')
}
})
})
Yes, this can solve your problem.
If there are several asserts with a little delay in test for example like below:
The
next
test will run beforelong run
ended, and the log seems wired...How about we pass a callback to the test function, so that the test runner could know the test ended. ex: