1.1.1 • Published 9 months ago
@fruster/test-utils v1.1.1
Fruster test utils
Utils for jasmine tests.
Start and stop a service beforeEach/beforeAll
Convenient method to start nats, connect bus, start mongo db and a service before each or all tests.
describe("Foo spec", () => {
// or use startBeforeAll
testUtils.startBeforeEach({
service: service,
bus: bus
});
});
If you need to do something after beforeAll/Each finished but before tests are started:
describe("Foo spec", () => {
// or use startBeforeAll
testUtils.startBeforeEach({
service: service,
bus: bus,
afterStart: (connection) => {
repo = new Repo(connection.db);
return Promise.resolve();
},
beforeStop: (connection) => {
// do something before connections are being stopped
// such as closing a HTTP server for example
}
});
});
Mock a service
Mock sequence of responses
To mock a service and return different response on each invocation:
const mockHello = testUtils.mockService({
// subject to listen on
subject: "foo-service.hello",
// array of responses, where first request will receive first response etc
responses: [
{
data: {
foo: "first response"
}
},
{
data: {
foo: "second response"
}
}
]
});
// Send requests
bus.request({
subject: "foo-service.hello",
req: {
data: "first request"
}
});
bus.request({
subject: "foo-service.hello",
req: {
data: "second request"
}
});
// Set expectations
expect(mockHello.invocations).toBe(2);
expect(mockHello.requests[0].data).tobe("first request");
expect(mockHello.requests[1].data).tobe("second request");
Mock a response
Perform expectations in callback:
const mockHelloWorld = testUtils.mockService({
subject: "foo-service.hello-world",
response: {
data: "hello world"
}
});
bus.request({
subject: "foo-service.hello-world",
req: {
data: "hello?"
}
});
expect(mockHelloWorld.requests[0].data).toBe("hello?")
1.1.1
9 months ago
1.1.0
9 months ago
1.0.0
11 months ago
1.0.0-1.0.0-alpha.20.0
11 months ago
1.0.0-alpha.19
1 year ago
1.0.0-alpha.18
1 year ago
1.0.0-alpha.17
1 year ago
1.0.0-alpha.15
3 years ago
1.0.0-alpha.10
3 years ago
1.0.0-alpha.12
3 years ago
1.0.0-alpha.11
3 years ago
1.0.0-alpha.14
3 years ago
1.0.0-alpha.13
3 years ago
1.0.0-alpha.8
3 years ago
1.0.0-alpha.7
3 years ago
1.0.0-alpha.6
3 years ago
1.0.0-alpha.4
3 years ago
1.0.0-alpha.3
3 years ago
1.0.0-alpha.2
3 years ago
1.0.0-alpha.0
3 years ago
1.0.0-alpha.1
3 years ago