Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdeepkhalsa/2856d89cb2c05039b0cb to your computer and use it in GitHub Desktop.
Save jasdeepkhalsa/2856d89cb2c05039b0cb to your computer and use it in GitHub Desktop.
Jasmine Dynamically Generated Tests
describe('add()', function() {
var tests = [
{bool: true, name: 'lol'},
{bool: true, name: 'a'},
{bool: true, name: 'b'},
{bool: true, name: 'b'}
];
tests.forEach(function(test) {
it('correctly adds ' + test.name + ' args', function() {
expect(true).toEqual(test.bool);
});
});
});
// => Output 4 Tests successfully completed
@jasdeepkhalsa
Copy link
Author

// Updated code style
const tests = [
    {bool: true,       name: 'lol'},
    {bool: true,    name: 'a'},
    {bool: true, name: 'b'},
    {bool: true, name: 'b'}
];

tests.forEach((test) => {
  describe(`This is testing ${test.name}`, () => {
    it('correctly adds ' + test.name + ' args', () => {
      expect(true).toEqual(test.bool);
    });
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment