Skip to content

Commit

Permalink
describe after hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
HookyQR committed Jul 12, 2019
1 parent ad4ff5f commit ac2b6e7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This improves readability and maintainability of the test code. Which in turn im
## Limitations
To provide this capability, the `set` and `subject` variables are defined on the global object. This means you run the risk of breaking the world if you choose the wrong variable names. But I'm sure this will just help you choose better names. ;) In reality, `JSSpec` doesn't allow you to overwrite an existing global variable. This doesn't save you if your application code sets some object on global. Of course, assigning to global in production code is a pretty bad idea anyway.

The ecosystem is not yet complete. The system does not yet have beforeEach, afterEach or after hooks.
The ecosystem is not yet complete. The system does not yet have beforeEach, or afterEach hooks.

Eventually there will be an expectation library to complement `JSSpec`. For now, `chai.expect` (or any similar assertion library) works fine.

Expand Down Expand Up @@ -123,12 +123,17 @@ it('is a thing', () => {
expect(subject).to.be.an.instanceOf(MyClass);
});
```

## Hooks
## `before([description, [options]], block)`
Define a before block to run before any `it` example block in this context. If no examples exit in the context, the `block` provided will not be run.

The `block` has access to lazy values (variables defined by `set` and `subject`), but (just like an example block) the values are reset at the end of the block execution. `before` blocks should be used to set external contexts - such as database entries, or file content - rather than setting variables to be used in the test code.

## `after([description, [options]], block)`
Define an after block to run after all `it` example block in this context. If no examples exit in the context, the `block` provided will not be run.

The `block` has access to lazy values (variables defined by `set` and `subject`), but (just like an example block) the values are reset at the end of the block execution. `after` blocks should be used to tear down external contexts - such as database entries, or file content - rather than doing anything with the test variables.

## eslint
There is an eslint plugin available which removes the 'is not defined' errors for variables defined in `set` and `subject` statements. Install with:

Expand Down

0 comments on commit ac2b6e7

Please sign in to comment.