BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
chaijs-bot on master
(data): Auto build _data (compare)
github-actions[bot] on v1.0.4
keithamus on master
fix: empty Symbol() returns Sym… (compare)
const chai = require('chai')
chai.use(require('chai-json-schema'))
const { expect } = chai
const RideSimulator = require('../src/RideSimulator')
describe('RideSimulator run()', () => {
it('should return a json compliant to the schema', () => {
let schema = { ... schema omitted ... }
let ride = new RideSimulator(1, 1)
ride.on('tick', (busData) => {
expect(busData).to.be.jsonSchema(schema)
})
})
})
const expectedJson = {
"authToken": "eyJraWQiOiJVdEI4c0hhYnk0aXBLNlwvQTZnaHBkRFFqRU9tdlptSnZZQTJpNFwvM2w3UmM9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIyMTVhMGVhZS00ZjkwLTRlODItOWY4Zi1lNzhlOTdkMzcyODAiLCJldmVudF9pZCI6ImVkNGY5MDJmLTFhM2UtNDRkYy1hNjg2LWY3ZjVjZDM3ODA5OCIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoiYXdzLmNvZ25pdG8uc2lnbmluLnVzZXIuYWRtaW4iLCJhdXRoX3RpbWUiOjE1NjUwOTk1OTAsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTIuYW1hem9uYXdzLmNvbVwvdXMtZWFzdC0yX2EzbE5SRU5QMSIsImV4cCI6MTU2NTEwMzE5MCwiaWF0IjoxNTY1MDk5NTkxLCJqdGkiOiJkMjY4YjRkMi01ZWVhLTQ4OGItODUyZi1lNGM4MWRmMWFiYzMiLCJjbGllbnRfaWQiOiI2Z2xwbmRxb2s2YWhua3M2dGFnNXQ5cGMwZyIsInVzZXJuYW1lIjoicWFAdGVsZXBhdGh5LmFpIn0.UlN9bucJbjS4nT8Ly0m9zKRctkyLp9hyIVt9v2l4GdyYptOAvPC3nJl3NrVJGRICAVXRZgswWqCDfifxYUaQ64XGNCrCkLMQ9ecgsNK5ZMuFl7ebl5m1bs3FZTyD-c2fAlzRlAGlLe5ADFN-IPBDI_lmkqd3bhA9wxPrPR7uc7HOl_rjUgsqDd0saO0OPw4AmGpuSqeT56XHoc_IuPUwk6KdPEJ4kO5pIz0hw__QNspMBsoOUrH1pt4TYD9dYTMyrFGJNhPDElJBrxFpGR1TIO7eiXAc_-8z-dhEY4Ek8fyPK8ULqEyk-0UD7QgXCe6TgqdD5jBVTB3aHTYpzn2gLg",
"clientInfo": {
"clientId": "0d6fc71d-46ff-4441-904f-9f5fd36a43a2"
}
}
ctx.should.do.foo(barFuncThatReturnsSmth)
and I'd like this chain to return the return value of barFuncThatReturnsSmth
this._obj
in the definition of the method foo
, but that didn't work. The object is there, but is not returned directly (it's hidden inside some __flags
object)
Anyone interested in an opensource project?
Spec oriented development speeds up programming by generating code based on tests/specs. Tests required will be the same or less specs as a normal developer writes.
https://github.com/Neur0plasticity/spec-dev
MSG me if interested
let = expect.to.be.Visible("myElementId");
@aeutalt You could add your own matcher method, https://www.chaijs.com/api/plugins/#addmethodctx-name-method
But I suspect there is some assertion library that someone has made for working with elements already that you could install
it('if test case', async function () {
var cardProcZero = await driver.hasElementByAccessibilityId("card_proc_0"); // looks up the element
var visivel = expect(cardProcZero).to.exist; // expects it to exist
if (cardProcZero == visivel) { // if it is visible, it clicks on it
it('test case 1', async function () {
await cardProcZero.click();
return true;
});
} else {
it('test case 2', async function () { // if it's not visible, it creates the element
let adicionarProc = await driver.waitForElementByAccessibilityId("button_addProcedimento");
await adicionarProc.click();
return false;
})
}
});
});
``
``` var chaiHttp = require("chai-http");
var chai = require("chai");
var assert = chai.assert;
var server = require("../server");
chai.use(chaiHttp);
suite("Functional Tests", function() {
test("POST =>Create a thread", function(done) {
chai.request(server)
.post("/api/threads/:board")
.type("form")
.send({
board: "test",
text: "Testing post request with Chai",
delete_password: "deleteChai!1234"
})
.end(function(err, res) {
chai.assert(res.status, 200);
chai.assert(
res.redirects[0].split("/").length - 1,
"test"
);
done();
});
});
test("GET =>Get threads", function(done) {
chai.request(server)
.get("/api/threads/test")
.end(function(err, res) {
chai.assert(res.body[0]["board"], "test");
chai.assert(
res.body[0]["text"],
"Testing post request with Chai"
);
done();
});
});
});```
var chaiHttp = require("chai-http");
var chai = require("chai");
var assert = chai.assert;
var server = require("../server");
chai.use(chaiHttp);
suite("Functional Tests", function() {
test("POST =>Create a thread", function(done) {
chai.request(server)
.post("/api/threads/:board")
.type("form")
.send({
board: "test",
text: "Testing post request with Chai",
delete_password: "deleteChai!1234"
})
.end(function(err, res) {
chai.assert(res.status, 200);
chai.assert(
res.redirects[0].split("/").length - 1,
"test"
);
done();
});
});
test("GET =>Get threads", function(done) {
chai.request(server)
.get("/api/threads/test")
.end(function(err, res) {
chai.assert(res.body[0]["board"], "test");
chai.assert(
res.body[0]["text"],
"Testing post request with Chai"
);
done();
});
});
});
import java.io.*;
import java.util.stream.IntStream;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
public class EcmaScriptTest {
public static void main(String[] args) throws Exception {
// Creating Rhino engine
Context context = Context.enter();
Scriptable globalScope = context.initStandardObjects();
//loading chai js lib
String[] jsFiles = { "chai.js" };
IntStream.range(0, jsFiles.length).forEach(i -> {
try {
context.evaluateReader(globalScope, new FileReader(jsFiles[i]), "ECMAScriptExecutor", 1, null);
} catch (Exception e) {
e.printStackTrace();
}
});
String res = "expect(false).to.not.be.test";
context.evaluateString(globalScope, res, "ECMAScriptExecutor", 1, null);
}