A lovely javascript testing framework -- want to contribute? join us in https://gitter.im/mochajs/contributors
juergba on karma
type check before calling retri… (compare)
how to compare with console contents. I try to using sinon js. But even calledOnce not working.
describe('', () => {
it('' () => {
const sandbox = sinon.createSandbox();
sandbox.spy(console, 'log');
somethingOutputConsoleLogFuc(param); // console.log is output
expect(console.log.calledOnce).to.be.true; // AssertionError: expected false to be true
expect(console.log.callWith(testResultConsoleContent)).to.be.true; // this part is what I really want to do
spy.restore();
})
})
I using sinon 13.0.1 and mocha is 9.1.4 version.
timeout
and retries
dilemma? https://stackoverflow.com/questions/68485310/mocha-retry-after-timeout
require.extensions
). Implementing the stackoverflow solution exactly, I get --compilers is DEPRECATED and no longer supported.
. If I replace --compilers png:./mochacfg.js
with --require ./mochacfg.js
, I get the same error TS2307: Cannot find module '../../media/xxx.png' or its corresponding type declarations.
as before. Reading the documentation, it seems that --require
can be used to import a transpiler like babel or typescript, or to load a custom file with hooks. However, I fail to see how I can replace png imports with an empty string for example with a hook. I am using node 16.14.0, mocha 9.1.0, babel/register 7.17.0, typescript 4.1.6, and create react app. 5.0.0. Thanks in advance
Hey so I ran a mocha test using IntelliJ's debugger, which automatically sets --timeout 0
. Left it paused for several minutes while looking at something, and when I resumed it, it timed out. Does setting this.timeout(xxx)
inside the script override the timeout set by --timeout
now? I don't recall this behaviour happening before I updated from v7 to v9. Previously if I debugged a test, it would ignore all thethis.timeout()
calls in the script
Guessing there's a new flag which does that behaviour, and Jetbrains needs to update their test runner? --no-timeouts
maybe?
:point_up: Edit: Hi all. I'm having trouble integrating mocha with a project that's already making heavy use of parcel 1.12, es-modules, and (probably most importantly) flow.
I have:
test/
subdirectory that simply imports code from another subdirectory (no assertions as of yet).$(npm bin)/mocha --require @babel/register test/
This fails with an "Unexpected identifier" error, which I believe is due to the runner getting the untransformed code.
I believe this because when i comment out the import itself, it runs to completion (but there's obviously nothing to test without the import). The tests contain no flow annotations as of yet.
What else might I check here?
DEBUG=mocha:*
I saw this lineHere is my problem; I pushed a setup to github: https://github.com/rasane/html5-dev-setup/blob/master/package.json#L8. in the commands, yarn run testw
runs on the console and tests are successful. but when I run those tests in the browser using yarn run testb
, I get the following error:
Uncaught TypeError: mocha_1.default.describe is not a function
look at the weird things I had to do here: https://github.com/rasane/html5-dev-setup/blob/master/test/index.spec.ts#L2 to make the tests run in console and browser. I wish that was not necessary.. so if someone has a better setup or can help me fix this setup , I will be greatful
I am trying to test for the database will not let me enter a duplicate
I expect it to throw error: duplicate key value violates unique constraint "team_per_tbl_pkey"
this indicates a PASS on the test. how do i trap it and assert against it?
it("will not let a person to be added to the same team twice", async () => {
try {
await startTrans(connection);
await setTestRoles(connection, per_oauth_sub);
let teamPerData = await connection.query(
sql.createSql,
sqlData.createValues
);
await endTrans(connection);
} catch (err) {
console.log(err.stack);
await rollBackTrans(connection);
}
{
throw Error;
}
});
Hello everyone, I am new to mocha. Is there a way to run a dynamic loop? I am trying to do something like the below (no need to be exact)
var testCaseList = [];
describe('dynamic loop', function () {
it('Obtain test case lists', function (done) {
getTestCase()
.then((testcases) => {
testCaseList = testcases; // this would be JSON array
done();
}).catch((error) => { done(error) });
});
// run loop that grabs from above method (getTestCase()).
testCaseList.forEach(({ test_case, version}) => {
it(`start test for ${test_case}`, function (done) {
expect(test_case}.equal(something);
}).catch((error) => { done(error) });
});
});
Basically, I am trying to run the loop test based on the list of test case from server, it is possible for mocha? Or it must be static? I tried to run before()
and successfully retrieve the list of test cases but it couldn't run for the forEach
.
node --inspect-brk ./node_modules/.bin/mocha dist/test/table.spec.js
it does stop and i can attach the debugger, but it does not stop in the mocha test file either...