Last active
August 29, 2015 14:14
-
-
Save tomduncalf/8077681a597c9bc3b8ab to your computer and use it in GitHub Desktop.
Attempt at a custom Jasmine matcher for ES6 Map equality testing, using the spread operator
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
import cfg from '../lib/config-parser'; | |
var customMatchers = { | |
toEqualMap: (util, customEqualityTesters) => { | |
return { | |
compare: (actual, expected) => { | |
var result = {}; | |
result.pass = util.equals([...actual], [...expected], customEqualityTesters); | |
if(!result.pass) { | |
result.message = `Expected map:\n${[...actual]} to equal\n${[...expected]}`; | |
} | |
return result; | |
} | |
}; | |
} | |
}; | |
describe("Config parser", () => { | |
beforeEach(() => { | |
jasmine.addMatchers(customMatchers); | |
}); | |
it("should parse an empty config", () => { | |
var result = cfg.parse(''); | |
var expected = new Map([]); | |
expect(result).toEqualMap(expected); | |
}); | |
it("should parse a config with no sections", () => { | |
var result = cfg.parse(`key1 = value1 | |
key2 = value2 | |
key with spaces = value with spaces | |
akey = avalue`); | |
var expected = new Map([ | |
['key1', 'value1'], | |
['key2', 'value2'], | |
['key with spaces', 'value with spaces'], | |
['akey', 'avalue'] | |
]); | |
expect(result).toEqualMap(expected); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any feedback welcome as I am not sure if this is a good way to do this or not