iensu / mocha-cakes-2 Goto Github PK
View Code? Open in Web Editor NEWA BDD plugin for Mocha testing framework
License: MIT License
A BDD plugin for Mocha testing framework
License: MIT License
small change, but i noticed that mocha cakes 2 doesn't handle context or specify. Which could be useful when we are trying to implement this.
Is it possible to provide a When
step that is executed by multiple scenarios, without duplicating the When call each time.
For example, we have many tests like this:
var unauthorizedScenarios =
[
{
description: "No Authorization Header",
givenDescription: "no authorization header is provided",
authHeader: null
},
{
description: "Invalid Authorization Header",
givenDescription: "an authorization header is provided in an incorrect format",
authHeader: "im-a-key"
}
];
unauthorizedScenarios.forEach(scenario => Scenario(scenario.description, function () {
Given(scenario.givenDescription, function () {
authHeader = scenario.authHeader
});
When("making an API request that requires authorization", async function () {
response = await request(config.baseUrl)
.get("payments/pay_y3oqhf46pyzuxjbcn2giaqnb44")
.set("Authorization", authHeader);
});
Then("it returns HTTP status code 401 (Unauthorized)", function () {
response.status.should.equal(401);
});
}));
What I don't like about this approach is the separation between the scenarios and the tests and it only works in cases where we have the same assertions.
What I would prefer to do is something like:
WhenEach("Doing something every time", function() {
});
ThenEach("Assert on every scenario in the feature", function() {
});
Scenario("Scenario 1", function() {
Given("Some context", function() {
});
Then("Scenario specific assertion", function() {
});
});
Essentially a WhenEach
, GivenEach
and ThenEach
would run on every scenario. I'm happy to send a PR for this if you can guide me on how best to hook into the scenarios.
Hi Jens! It seems that the latest version (3.0.0) is not released on npm yet. Would you be kind and publish it? :)
mocha-parallel-tests
is a package that allows Mocha tests to run in separate processes.
It is a wrapper of Mocha.
However when running tests in parallel that have mocha-cakes-2
in the ui
, it doesn't work.
Error:
ReferenceError: feature is not defined
Is there away to customise Mocha-cakes-2 output? i.e. the equivalent of Custom Reporters for mocha.
In some scenarios (i.e. automated runs) we would prefer output to be:
Hey there,
I am trying to implement this using spectron and discovered that when calling wdio functions, the whole thing errors out with the error,
at Layer.handle [as handle_request] (../node_modules/express/lib/router/layer.js:95:5)
If you run this with version 3.1.0, it will crash... 3.0.0 worked fine before.
'use strict';
describe('everything', () => {
it('should work', () => {
true.should.equal.true;
});
});
I love the semantics this library adds to my tests.
In particular, I love how this allows me to write "sequential steps", which are clearly dependent on each other. For example:
Given("I have an apple", ...);
When("I eat the apple", ...);
Then("I feel full", ...);
And("I feel healthy", ...);
This gives me very clear "arrange", "act", and "assert" sections (Given, When, Then
).
Now imagine that one of my "arrange" or "act" steps fails -- eg. I fail to "eat the apple".
Unfortunately, this results in 3 failed tests.
However, that's not quite what I expect. When an "arrange" or "act" fails, I would expect the "assertions" to be skipped. In other words, if a Given
or When
fails, all Thens
should be skipped. And / But
would probably be best categorized based on what preceded them.
Does this make sense? I half-expected this to be the existing behavior, but a quick test reveals that if any Given/When
fails, the rest of the assertions are still executed (which often gives confusing results).
Hey iensu,
Notice a lot of activity with mocha-cakes-2 as of late!
Was curious if you'd be interested in merging the projects (I am not sure how this would work, but it'll be cool to try). Since mocha-cakes
(coffee-script version) haven't been updated in 6 years, thought you'd like to have the npm project name. ๐
Hi,
Is it possible to create data driven tests with this library? I am using this with chakram and would like to avoid creating multiple test cases for same same assertion. Any examples? Thanks,
Awesome job porting this project from CoffeeScript, I really liked it but was having trouble with using CoffeeScript to write my tests. I've modified the code slightly to clean the output a bit by giving the Feature
a new line before it and removing the one after, but I'd really like to reduce the lines required for the step to a having no spaces, any idea how I can do this?
=== User model ===
Feature: Unit: #register
Scenario: failure, ValidationError
โ Given: a failing email and password combination
โ When: account registration is attempted
โ Then: the registration should fail with a ValidationError for a missing em
ail and password
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.