Last active
December 26, 2021 08:11
-
-
Save omril1/112e1dddacc025d538d668fb5620cdcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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