Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nesting ability added #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .storybook/__tests__/sample.ci.jest.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
6 changes: 6 additions & 0 deletions .storybook/__tests__/sample.ci.mocha.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
10 changes: 9 additions & 1 deletion .storybook/__tests__/sample.stories.js
Original file line number Diff line number Diff line change
@@ -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";


Expand All @@ -18,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);
Expand Down
14 changes: 12 additions & 2 deletions src/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import addons from '@storybook/addons';
import { EVENT_ID } from './';

let currentStory = "";
const subStory = [];
const results = {};
const beforeEachFunc = {};
const afterFunc = {};
Expand All @@ -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 = () => {
Expand Down