1
|
|
|
import chai from 'chai'; |
2
|
|
|
|
3
|
|
|
import CodingameError from '../../src/codingame/error.js'; |
4
|
|
|
|
5
|
|
|
let expect = chai.expect; |
6
|
|
|
|
7
|
|
|
describe(`[module] codingame/error`, function() { |
8
|
|
|
describe(`[method] constructor`, function() { |
9
|
|
|
it(`should create a default CodingameError with empty message`, function() { |
10
|
|
|
let error = new CodingameError(); |
11
|
|
|
expect(error).to.be.an.instanceof(CodingameError).and.has.a.property(`message`).empty; |
|
|
|
|
12
|
|
|
}); |
13
|
|
|
it(`should create a CodingameError with the specified message`, function() { |
14
|
|
|
let message = `Specified message`; |
15
|
|
|
let error = new CodingameError(message); |
16
|
|
|
expect(error).to.be.an.instanceof(CodingameError).and.has.a.property(`message`, message); |
17
|
|
|
}); |
18
|
|
|
it(`should create a CodingameError from an Error`, function() { |
19
|
|
|
let message = `Some error`; |
20
|
|
|
let error = new Error(message); |
21
|
|
|
let cgerror = new CodingameError(error); |
22
|
|
|
expect(cgerror).to.be.an.instanceof(CodingameError).and.has.a.property(`message`, message); |
23
|
|
|
}); |
24
|
|
|
}); |
25
|
|
|
describe(`[method] metadata`, function() { |
26
|
|
|
it(`should attach metadatas to the CodingameError`, function() { |
27
|
|
|
let value = `42`; |
28
|
|
|
let meta = { "property": value }; |
29
|
|
|
let error = new CodingameError(); |
30
|
|
|
error.attach(meta); |
31
|
|
|
expect(error).to.have.a.property(`property`, value); |
32
|
|
|
}); |
33
|
|
|
it(`should not replace 'name' and 'message' properties`, function() { |
34
|
|
|
let value = 42; |
|
|
|
|
35
|
|
|
let meta = { |
36
|
|
|
"name": `myname`, |
37
|
|
|
"message": `Not an error message` |
38
|
|
|
}; |
39
|
|
|
let message = `Error message`; |
40
|
|
|
let error = new CodingameError(message); |
41
|
|
|
error.attach(meta); |
42
|
|
|
expect(error).to.have.a.property(`name`, `CodingameError`); |
43
|
|
|
expect(error).to.have.a.property(`message`, message); |
44
|
|
|
}); |
45
|
|
|
}); |
46
|
|
|
}); |
47
|
|
|
|