의 배열 나는이 유사한 코드를 및 getter.모카, 배열 및 범위
이const Foo = require('./../foo.js'),
source = [[1, 2, 3], [4, 5, 6]],
chai = require('chai'),
expect = chai.expect;
describe('Foo',() => {
describe('bar',() => {
it('expect to modify the array',() => {
let foo = new Foo(source);
foo.bar();
expect(foo.a).to.deep.equal([[1, [1], 3], [4, [1], 6]]);
});
});
describe('get',() => {
it('expect to return the array',() => {
let foo = new Foo(source);
expect(foo.get()).to.deep.equal([1, 2, 3]);
});
});
});
있는 내가 처음에 source
변수를 선언하고 새로운 Foo
각 테스트를 구축하는 데 사용
는 지금은 모카로, 단위 테스트를 작성.
그러나, 결과는 ... bar
테스트는 get
시험에 foo
의 속성을 수정하는 것이 : 아무것도 변경되지 않습니다 모카 시험 대신 화살표 기능의 익명 함수를 사용
Foo
bar
✓ expect to modify the array
get
1) expect to return the array
1 passing (19ms)
1 failing
1) Foo get expect to return the array:
AssertionError: expected [ [ 1, [ 1 ], 3 ], [ 4, [ 1 ], 6 ] ] to deeply equal [ 1, 2, 3 ]
+ expected - actual
[
- [
- 1
- [
- 1
- ]
- 3
- ]
- [
- 4
- [
- 1
- ]
- 6
- ]
+ 1
+ 2
+ 3
]
at Proxy.assertEqual (node_modules/chai/lib/chai/core/assertions.js:1020:19)
at Proxy.methodWrapper (node_modules/chai/lib/chai/utils/addMethod.js:57:25)
at Context.it (test/foo.js:20:30)
, splice
을 사용하여 소스를 값으로 복사 할 수도 있습니다.
내가 무엇을 놓쳤습니까? 그것은 분명히 두 배열의 동일한 참조를 모두 foo
의 속성에 기인 한 것이 분명합니다. 그러나 더 중요한 것은 내가 어떻게 만들 수 있는지를 알아낼 수 없습니다. foo
을 분리하십시오.
@Jonasw 실제 코드, 검사가 실패 : t는 케이 있도록 만들어진다 – DrakaSAN