storybook-addon-specifications
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -27,3 +27,3 @@ import React from "react"; | ||
stories.add('Hello World', function () { | ||
specs(buttonSpecs); | ||
specs(() => buttonSpecs); | ||
return helloWorldStory; | ||
@@ -38,3 +38,3 @@ }); | ||
const helloEarthSpecs = describe('Hello Earth', function () { | ||
it('Should indicate that only one item is left', function () { | ||
it('Should have the Hello Earth label', function () { | ||
let output = mount(helloEarthStory); | ||
@@ -46,4 +46,4 @@ expect(output.text()).toContain('Hello Earth'); | ||
stories.add('Hello Earth', function () { | ||
specs(helloEarthSpecs); | ||
specs(() => helloEarthSpecs); | ||
return helloEarthStory; | ||
}); |
@@ -26,3 +26,3 @@ import React from "react"; | ||
stories.add('Hello World', function () { | ||
specs(buttonSpecs); | ||
specs(() => buttonSpecs); | ||
return helloWorldStory; | ||
@@ -44,4 +44,4 @@ }); | ||
stories.add('Hello Earth', function () { | ||
specs(helloEarthSpecs); | ||
specs(() => helloEarthSpecs); | ||
return helloEarthStory; | ||
}); |
@@ -16,3 +16,3 @@ import React from "react"; | ||
specs(describe('Hello World', function () { | ||
specs(() => describe('Hello World', function () { | ||
it('Should have the Hello World label', function () { | ||
@@ -30,2 +30,2 @@ let output = mount(helloWorldStory); | ||
return helloWorldStory; | ||
}); | ||
}); |
@@ -17,19 +17,23 @@ 'use strict'; | ||
var results = { | ||
goodResults: [], | ||
wrongResults: [] | ||
}; | ||
var currentStory = ""; | ||
var results = {}; | ||
function specs(specs) { | ||
specs(); | ||
var storyName = specs(); | ||
// get `channel` from the addon API | ||
var channel = _storybookAddons2.default.getChannel(); | ||
// send the message using the channel | ||
channel.emit(_.EVENT_ID, { results: results }); | ||
channel.emit(_.EVENT_ID, { results: results[storyName] }); | ||
} | ||
var describe = exports.describe = function describe(desc, func) { | ||
results.goodResults = []; | ||
results.wrongResults = []; | ||
return func; | ||
var describe = exports.describe = function describe(storyName, func) { | ||
currentStory = storyName; | ||
results[currentStory] = { | ||
goodResults: [], | ||
wrongResults: [] | ||
}; | ||
func(); | ||
return storyName; | ||
}; | ||
@@ -40,6 +44,6 @@ | ||
func(); | ||
results.goodResults.push(desc); | ||
results[currentStory].goodResults.push(desc); | ||
} catch (e) { | ||
results.wrongResults.push({ spec: desc, message: e.message }); | ||
results[currentStory].wrongResults.push({ spec: desc, message: e.message }); | ||
} | ||
}; |
{ | ||
"name": "storybook-addon-specifications", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Add tests to your react storybook stories", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -23,2 +23,4 @@ # Specifications Addon | ||
The first parameter of the describe function **must be the same** as the story's name. | ||
```js | ||
@@ -39,3 +41,3 @@ import { storiesOf } from '@kadira/storybook' | ||
specs(describe('Hello World', function () { | ||
specs(() => describe('Hello World', function () { | ||
it('Should have the Hello World label', function () { | ||
@@ -74,5 +76,5 @@ let output = mount(helloWorldStory); | ||
But because this addon redefine describe and it functions, you'll need some extra-configuration to make the tests pass within the test runner. | ||
You'll also need to declare to change a little bit your stories declaration (see ./.storybook/__tests__/sample.ci.jest.stories.js file as an example) | ||
You'll also need to change a little bit your stories declaration (see ./.storybook/__tests__/sample.ci.jest.stories.js file as an example) | ||
You'll find in this directory the example using JEST or MOCHA. | ||
You'll find in this directory examples using JEST or MOCHA. | ||
@@ -79,0 +81,0 @@ ### Using JEST |
import addons from '@kadira/storybook-addons'; | ||
import { EVENT_ID } from './'; | ||
const results = { | ||
goodResults: [], | ||
wrongResults: [] | ||
}; | ||
let currentStory = ""; | ||
const results = {}; | ||
export function specs(specs) { | ||
specs(); | ||
// get `channel` from the addon API | ||
const channel = addons.getChannel(); | ||
// send the message using the channel | ||
channel.emit(EVENT_ID, {results}); | ||
let storyName = specs(); | ||
// get `channel` from the addon API | ||
const channel = addons.getChannel(); | ||
// send the message using the channel | ||
channel.emit(EVENT_ID, {results : results[storyName]}); | ||
} | ||
export const describe = (desc, func) => { | ||
results.goodResults = []; | ||
results.wrongResults = []; | ||
return func; | ||
export const describe = (storyName, func) => { | ||
currentStory = storyName; | ||
results[currentStory] = { | ||
goodResults: [], | ||
wrongResults: [] | ||
}; | ||
func(); | ||
return storyName; | ||
}; | ||
@@ -26,7 +30,7 @@ | ||
func(); | ||
results.goodResults.push(desc); | ||
results[currentStory].goodResults.push(desc); | ||
} catch (e) { | ||
results.wrongResults.push({spec: desc, message: e.message}); | ||
results[currentStory].wrongResults.push({spec: desc, message: e.message}); | ||
} | ||
}; | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
213405
554
170