Skip to content

Instantly share code, notes, and snippets.

@omril1
Last active December 26, 2021 08:11
Show Gist options
  • Save omril1/112e1dddacc025d538d668fb5620cdcc to your computer and use it in GitHub Desktop.
Save omril1/112e1dddacc025d538d668fb5620cdcc to your computer and use it in GitHub Desktop.
const { context } = require('testim'); /* Magic */
describe('my dynamic scope test', () => {
let something = 'anything';// Can't access this variable, we can only use context
function addFoo() {
let name = context.getVar('name') || '';
name = name + 'foo';
context.setVar('name', name);
}
function addBar() {
let name = context.getVar('name') || '';
name = name + 'bar';
context.setVar('name', name);
addFoo(); // This does affect the name in current scope
}
it('should fail', () => {
addBar();
let name = context.getVar('name');
expect(name).toBe('bar'); // Name is actually foobar
});
});
describe('my test', () => {
let something = 'anything';// Can access this variable
function addFoo() {
let name = '';
name = name + 'foo';
return name;
}
function addBar() {
let name = '';
name = name + 'bar';
addFoo(); // This doesn't affect the name in current scope
return name;
}
it('should pass', () => {
expect(addBar()).toBe('bar');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment