AssertionError:期望{Object($ typeof,type,...)}深度相等{Object($ typeof,type,...)}

时间:2016-03-31 18:10:28

标签: javascript html reactjs mocha chai

整个错误和代码:https://gist.github.com/js08/1c80a53fe8666b2a207bf9d961bdaa3d

  • 我在测试用例中遇到错误..
  • 如果我有移动平台,它应该呈现特定的dom结构......
  • 所以我将jsx中的返回项目传递给预期变量..
  • 使用下面的行检查这个预期的testRenderer。 期望(testRenderer.getRenderOutput())to.deep.equal(预期);
  • 我在这一行面临错误

错误

```js

 1) "SportsTopPortion" Unit Tests native build env should render mobile built view:

      AssertionError: expected { Object ($typeof, type, ...) } to deeply equal { Object ($typeof, type, ...) }
      + expected - actual

               "_owner": [null]
               "_store": {}
               "key": [null]
               "props": {
      -          "children": {
      -          

      at Assertion.assertEqual (C:\sports-whole-package\node_modules\chai\lib\chai\core\assertions.js:455:19)
      at Assertion.ctx.(anonymous function) [as equal] (C:\sports-whole-package\node_modules\chai\lib\chai\utils\addMethod.js:40:25)
      at Context.<anonymous> (C:/codebase/sports-template-standard/test/components/SportsTopPortion/SportsTopPortion-unit-tests.js:105:60)
      at callFn (C:\sports-whole-package\node_modules\mocha\lib\runnable.js:286:21)
      at Test.Runnable.run (C:\sports-whole-package\node_modules\mocha\lib\runnable.js:279:7)
      at Runner.runTest (C:\sports-whole-package\node_modules\mocha\lib\runner.js:421:10)
      at C:\sports-whole-package\node_modules\mocha\lib\runner.js:528:12
      at next (C:\sports-whole-package\node_modules\mocha\lib\runner.js:341:14)
      at C:\sports-whole-package\node_modules\mocha\lib\runner.js:351:7
      at next (C:\sports-whole-package\node_modules\mocha\lib\runner.js:283:14)
      at Immediate._onImmediate (C:\sports-whole-package\node_modules\mocha\lib\runner.js:319:5)
```


test case


```js
import {expect} from 'chai';
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import {SportsTopPortion} from '../../../src/components/sports-top-portion/sports-top-portion.jsx';
require('../../test-utils/dom');


describe('"sports-top-portion" Unit Tests', function() {
    let shallowRenderer = TestUtils.createRenderer();

    let sportsContentContainerLayout ='mobile';
    let sportsContentContainerProfile = {'exists': 'hasSidebar'};
    let sportsContentContainerAuthExchange = {hasValidAccessToken: true};
    let sportsContentContainerHasValidAccessToken ='test'; 



    describe('native build env', function() {

        console.log("native build------->");

        before(function() {
            console.log("inside before------->");
            process.env.sports_PLATFORM= 'mobile';
        });

        after(function() {
            console.log("inside after------->");
            delete process.env.sports_PLATFORM;
        });

        it('should render mobile built view', function() {


            let testRenderer = new ReactTestRenderer(<SportsTopPortion sportsWholeFramework={sportsContentContainerLayout} sportsPlayers={sportsContentContainerProfile} sportsAuthentication={sportsContentContainerAuthExchange} sportsUpperBar={{activeSportsLink:'test'}} />);


            let onClose = function() {
               console.log("------------>bar");
            };

            let expected = (
                <header role="banner">
                    <a href="/" className="sportsTopPortion-iconLink">
                        <img src="~^img,header-logo.svg~^" className="sportsTopPortion-icon" alt="sports Home"/>
                    </a>
                    <HeaderDropMask header={{activeMenu:'test'}} onClose={onClose} />
                </header>
            );

console.log(("testRenderer------->" + JSON.stringify(testRenderer.getRenderOutput())));
console.log(("expected------->" + JSON.stringify(expected)));


            expect(testRenderer.getRenderOutput()).to.deep.equal(expected);
        });

    })



});
```

0 个答案:

没有答案