From 7ebe8dc87d9b1fa3d08438be03df2f7263afbf2f Mon Sep 17 00:00:00 2001 From: "Curtis M. Humphrey, Ph.D" Date: Thu, 7 Sep 2017 13:04:39 -0500 Subject: [PATCH 1/3] nesting ability added --- src/preview.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/preview.js b/src/preview.js index 1ecd04b..e3438d7 100644 --- a/src/preview.js +++ b/src/preview.js @@ -2,6 +2,7 @@ import addons from '@storybook/addons'; import { EVENT_ID } from './'; let currentStory = ""; +const subStory = []; const results = {}; const beforeEachFunc = {}; const afterFunc = {}; @@ -14,14 +15,23 @@ export function specs(specs) { } export const describe = (storyName, func) => { - currentStory = storyName; - results[currentStory] = { goodResults: [], wrongResults: [] }; + let first_describe = false + if (currentStory === "") { + first_describe = true + currentStory = storyName; + results[currentStory] = { goodResults: [], wrongResults: [] }; + } else { + subStory.push(storyName) + } func(); if(afterFunc[currentStory]) afterFunc[currentStory](); + subStory.pop() + if (first_describe) currentStory = "" return storyName; }; export const it = function(desc, func) { + if (subStory.length) desc = subStory.join(" > ") + ": " + desc const storyName = currentStory; const pushGoodResult = () => { From 35203d5c91dc4ea2516a070c918185f6a460681e Mon Sep 17 00:00:00 2001 From: "Curtis M. Humphrey, Ph.D" Date: Tue, 17 Apr 2018 08:16:28 -0500 Subject: [PATCH 2/3] fixed enzyme init problem for storybook --- .storybook/__tests__/sample.stories.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.storybook/__tests__/sample.stories.js b/.storybook/__tests__/sample.stories.js index 1a72840..0af4ffe 100644 --- a/.storybook/__tests__/sample.stories.js +++ b/.storybook/__tests__/sample.stories.js @@ -1,7 +1,9 @@ import React from "react"; import {storiesOf, action} from '@storybook/react' import { specs, describe, it} from '../../src' -import {mount} from "enzyme"; +import Enzyme, {mount} from "enzyme" +import Adapter from "enzyme-adapter-react-16" +Enzyme.configure({ adapter: new Adapter() }); import expect from "expect"; From 6b4e1e970f106d8a1e5e4589856056646cc9b3d8 Mon Sep 17 00:00:00 2001 From: "Curtis M. Humphrey, Ph.D" Date: Tue, 17 Apr 2018 08:16:39 -0500 Subject: [PATCH 3/3] added to stories to show nesting --- .storybook/__tests__/sample.ci.jest.stories.js | 6 ++++++ .storybook/__tests__/sample.ci.mocha.stories.js | 6 ++++++ .storybook/__tests__/sample.stories.js | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/.storybook/__tests__/sample.ci.jest.stories.js b/.storybook/__tests__/sample.ci.jest.stories.js index f85ec70..9a435e0 100644 --- a/.storybook/__tests__/sample.ci.jest.stories.js +++ b/.storybook/__tests__/sample.ci.jest.stories.js @@ -33,6 +33,12 @@ stories.add('Hello World', function () { expect(output.text()).toContain('Hello World'); }); + describe('Expects should work nexted too', () => { + it('Should have the Hello World label', function () { + expect(output.text()).toContain('Hello World'); + }); + }); + })); return helloWorldStory; }); diff --git a/.storybook/__tests__/sample.ci.mocha.stories.js b/.storybook/__tests__/sample.ci.mocha.stories.js index 4f028d7..4678b6a 100644 --- a/.storybook/__tests__/sample.ci.mocha.stories.js +++ b/.storybook/__tests__/sample.ci.mocha.stories.js @@ -37,6 +37,12 @@ stories.add('Hello World', function () { expect(output.text()).toContain('Hello World'); }); + describe('Expects should work nexted too', () => { + it('Should have the Hello World label', function () { + expect(output.text()).toContain('Hello World'); + }); + }); + })); return helloWorldStory; }); diff --git a/.storybook/__tests__/sample.stories.js b/.storybook/__tests__/sample.stories.js index 0af4ffe..1c05e39 100644 --- a/.storybook/__tests__/sample.stories.js +++ b/.storybook/__tests__/sample.stories.js @@ -20,6 +20,12 @@ stories.add('Hello World', function () { let output = mount(helloWorldStory); expect(output.text()).toContain('Hello Wrld'); }); + describe('Expects should work nexted too', () => { + it('Should have the Hello World label', function () { + let output = mount(helloWorldStory); + expect(output.text()).toContain('Hello Wrld'); + }); + }); it('Should have the Hello World label', function () { let output = mount(helloWorldStory);