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

correct jasmine behavior #47

Open
wants to merge 1 commit 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
4 changes: 2 additions & 2 deletions src/getContextInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function jasmineContextMatcher(rawStack: string): ContextInfo | undefined {
if (!/(jasmine\.js|jasmine\/lib\/loader\.js)/.test(rawStack)) {
return undefined;
}
if (!/Env\.describe/.test(rawStack)) {
if (!/Env\.describe|Env\/this.describe/.test(rawStack)) {
return {
allowed: false,
message: 'given must be called inside a describe',
Expand All @@ -67,7 +67,7 @@ export default function getContextInfo(ssf: Function): ContextInfo {
}
throw err;
} catch (e) {
rawStack = e.stack;
rawStack = (e as any).stack;
}
let context: ContextInfo | undefined;

Expand Down
35 changes: 25 additions & 10 deletions src/getGivenFunc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,45 @@ const getGivenFunc = () => {
}
};

let testRunnerBeforeAll: (f: () => void) => void;
let testRunnerAfterAll: (f: () => void) => void;

if (typeof beforeAll === 'function') {
beforeAll(push);
testRunnerBeforeAll = beforeAll;
} else if (typeof before === 'function') {
before(`givens setup ${key}`, push);
testRunnerBeforeAll = (f: () => void) => before(`givens setup ${key}`, f)
} else {
throw new GivenError('no test runner found', given);
}

if (typeof afterAll === 'function') {
afterAll(pop);
testRunnerAfterAll = afterAll;
} else if (typeof after === 'function') {
after(`givens teardown ${key}`, pop);
testRunnerAfterAll = (f: () => void) => after(`givens teardown ${key}`, f);
} else {
throw new GivenError('no test runner found', given);
}

try {
testRunnerBeforeAll(push)
testRunnerAfterAll(pop)
} catch(e) {
console.log(e);
throw new GivenError('cannot call given from a test or lifecycle hook', given);
}
};
if (typeof afterEach === 'function') {
// clear the cache after every test
afterEach(() => {
const cache = (given as any).__cache__;
Object.keys(cache).forEach((key: any) => {
delete cache[key];
try {
// clear the cache after every test
afterEach(() => {
const cache = (given as any).__cache__;
Object.keys(cache).forEach((key: any) => {
delete cache[key];
});
});
});
} catch(e) {
throw new GivenError('cannot call given from a test or lifecycle hook', given);
}
} else {
throw new GivenError('no test runner found', getGivenFunc);
}
Expand Down