我已经运行它并且它出现了错误错误,我该如何解决?我希望保持这个expect(bc.isValidChain(bc2.chain)).toBe(true);
是真正的价值而不是虚假。
blockchain.test.js
const Blockchain = require('./blockchain');
const Block = require('./block');
describe('Blockchain', () => {
let bc, bc2;
beforeEach (() => {
bc = new Blockchain();
bc2 = new Blockchain();
});
it('starts with genesis block', ()=> {
expect(bc.chain[0]).toEqual(Block.genesis());
});
it('adds a new block', () => {
const data = 'foo';
bc.addBlock(data);
expect(bc.chain[bc.chain.length-1].data).toEqual(data);
});
it('validates a valid chain', () => {
bc2.addBlock('foo');
expect(bc.isValidChain(bc2.chain)).toBe(true);
});
it('invalidates a chain with a corrupt genesis block', () => {
bc2.chain[0].data = 'Bad data';
expect(bc.isValidChain(bc2.chain)).toBe(false);
});
it('invalidates a corrupt chain', () => {
bc2.addBlock('foo');
bc2.chain[1].data = 'Not foo';
expect(bc.isValidChain(bc2.chain)).toBe(false);
});
});
git bamp run
● Blockchain › validates a valid chain
expect(received).toBe(expected) // Object.is equality
Expected value to be:
true
Received:
false
24 | bc2.addBlock('foo');
25 |
> 26 | expect(bc.isValidChain(bc2.chain)).toBe(true);
27 | });
28 |
29 | it('invalidates a chain with a corrupt genesis block', () => {
at Object.it (blockchain.test.js:26:38)
PASS .\block.test.js
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 failed, 6 passed, 7 total
Snapshots: 0 total
Time: 0.209s, estimated 1s
Ran all test suites.