Domain
Application
Framework
Adapters
End-to-end
test
Domain
Application
Framework
Adapters
browser
.signup({email, password})
.logout()
.assert.visible('.login')
.login({email, password:'wrong pass'})
.waitForElementVisible('.error', 5000)
.assert.containsText('.error', 'Wrong password')
.login({email, password})
.waitForUrlChange({timeout: 5000})
.assert.urlContains('/dashboard')
.assert.visible('.logout')
.end();
Selenium
Phantom Js
Nightwatch
docker
describe("camel case",()=>{
it("convert 'camel case' to 'camelCase'", ()=>{
/* given */
var caser = new Caser();
/* when */
var answer = caser.toCamelCase('hello world');
/* then */
assertThat(answer, equalTo('helloWorld'))
})
})
describe("camel case",()=>{
it("convert `camel case` to `camelCase`", ...)
it("convert `Camel Case` to `camelCase`", ...)
it("convert `CamelCase` to `camelCase`", ...)
it("convert `camel-case` to `camelCase`", ...)
it("convert `camel_case` to `camelCase`", ...)
})
/* returns `undefined` */
messageSender.sendMessage("foo bar");
"given" phase
"then" phase
describe("MessagesSender",()=>{
it("should send a message", ()=>{
var server = Mock(ServerApi);
/* given */
var ms = new MessagesSender(server);
/* when */
ms.sendMessage("foo bar");
/* then */
assertThat(server.postMsg, wasCalledWith("foo%20bar"))
})
})
describe("MessagesSender",()=>{
it("should fail if server returns 404", ()=>{
var server = Stub(ServerApi);
/* given */
whenCalled(server.get).returns({statusCode:404});
var ms = new MessagesSender(server);
/* when */
var res = ms.sendMessage("foo bar");
/* then */
assertThat(res, hasProperty('error',"404 NOT FOUND"))
})
})
it("should render todo items", () => {
/* given */
var provider = Stub(TodoListProvider);
provider.getTodos.returns(Promise.resolve([t1,t2,t3])
/* when */
var instance = shallow(
<TodoList provider={provider} />
);
/* then */
assertThat(instance.find(TodoItem), hasSize(3));
});
Mocha
Sinon
Hamjest
Chai
var messagesStore =
new MessagesStore("http://localhost:8080");
// how to test this?!
messagesStore.postMessage("hello world")
it("should save messages", () => {
// given
var messagesStore =
new MessagesStore("http://localhost:8080");
// when
return messagesStore.postMessage("hello world")
.then(()=> messagesStore.getMessage())
.then(messages=> {
assertThat(messages, hasSize(1));
assertThat(messages[0], equalsTo("hello world");
})
});
Karma
Request
JQuery
enzyme
Jasmine