Skip to content

'Cannot convert a Symbol value to a string' when i test react. #2856

@MrKou47

Description

@MrKou47

Expected behaviour

No Error.

Actual behaviour

  test component
    ✖ test demo component
      Chrome 62.0.3202 (Mac OS X 10.12.6)
    TypeError: Cannot convert a Symbol value to a string
        at ContextKarma.stringify (context.js:75:34)
        at ContextKarma.log (context.js:138:24)
        at console.localConsole.(anonymous function) [as log] (context.js:242:16)
        at Context.<anonymous> (test.webpack.js:9:576885)

Environment Details

{
  "dependencies": {
    "autoprefixer": "^7.1.4",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "clean-webpack-plugin": "^0.1.16",
    "css-loader": "^0.28.7",
    "extract-text-webpack-plugin": "^3.0.0",
    "html-webpack-plugin": "^2.30.1",
    "moment": "^2.19.1",
    "node-sass": "^4.5.3",
    "postcss-loader": "^2.0.6",
    "prop-types": "^15.6.0",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-router": "^3.2.0",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.18.2",
    "webpack": "^3.6.0",
    "webpack-dev-server": "^2.8.2",
    "webpack-module-hot-accept": "^1.0.5"
  },
  "devDependencies": {
    "babel-plugin-transform-es2015-modules-umd": "^6.24.1",
    "babel-register": "^6.26.0",
    "chai": "^4.1.2",
    "expect": "^21.2.1",
    "karma": "^1.7.1",
    "karma-babel-preprocessor": "^7.0.0",
    "karma-chai": "^0.1.0",
    "karma-chrome-launcher": "^2.2.0",
    "karma-coverage": "^1.1.1",
    "karma-mocha": "^1.3.0",
    "karma-mocha-reporter": "^2.2.5",
    "karma-webpack": "^2.0.5",
    "mocha": "^4.0.1",
    "react-addons-test-utils": "^15.6.2",
    "react-hot-loader": "^3.0.0"
  }
}
// karma.conf.js
module.exports = function(config) {
  config.set({

    basePath: '',

    frameworks: ['mocha', 'chai'],

    files: [
      // '__test__/**/*.spec.js'
      'test.webpack.js'      
    ],

    exclude: [
      '**/*.swp',
      'src/router.config.js'
    ],


    preprocessors: {
      'test.webpack.js': ['webpack', 'coverage'],
    },

    webpack: {
      devtool: 'inline-source-map',
      resolve: {
        extensions: ['.js', '.jsx'],
      },
      module: {
        rules: [{
          test: /\.jsx?$/,
          use: {
            loader: 'babel-loader',
            options: {
              presets: ['react', 'es2015', 'stage-0'],
              plugins: ['transform-runtime']
            },
          },
          exclude: /(node_modules|bower_components)/,
        },]
      },
    },
    webpackMiddleware: {
      noInfo: true
    },

    reporters: ['mocha', 'coverage'],

    port: 9876,

    colors: true,

    logLevel: config.LOG_INFO,

    autoWatch: true,

    browsers: ['Chrome'],

    singleRun: false,

    concurrency: Infinity,

    coverageReporter: {
      reporters:[
        {type: 'html', dir: 'coverage/'},
        {type: 'text-summary'}
      ],
    }
  })
}

Steps to reproduce the behaviour

// __test__/demo.spec.js
import React from 'react';
import { expect } from 'chai';
import TestUtils from 'react-dom/test-utils';

class Common extends React.Component {
  render() {
    return (
      <div>hello world</div>
    )
  }
}

describe('test component', () => {
  it('test demo component', () => {
    const renderer = TestUtils.createRenderer();
    renderer.render(<Common />);
    const output = renderer.getRenderOutput();
    console.log(output); // NOTE! If i delete this code. Karma will be ok. But why can't i console this result and how to fix this?
  })
})
  1. npm test

Chrome 62.0.3202 (Mac OS X 10.12.6) LOG: 'p1'
ERROR: 'Warning: Shallow renderer has been moved to react-test-renderer/shallow. Update references to remove this warning.'
  test component
    ✖ test demo component
  Test util
    ✔ should return params

Finished in 0.263 secs / 0.015 secs @ 17:15:37 GMT+0800 (CST)

SUMMARY:
✔ 1 test completed
✖ 1 test failed

FAILED TESTS:
  test component
    ✖ test demo component
      Chrome 62.0.3202 (Mac OS X 10.12.6)
    TypeError: Cannot convert a Symbol value to a string
        at ContextKarma.stringify (context.js:75:34)
        at ContextKarma.log (context.js:138:24)
        at console.localConsole.(anonymous function) [as log] (context.js:242:16)
        at Context.<anonymous> (test.webpack.js:9:576885)


=============================== Coverage summary ===============================
Statements   : 35.85% ( 3670/10236 )
Branches     : 10.64% ( 718/6749 )
Functions    : 34.76% ( 640/1841 )
Lines        : 36.2% ( 3649/10081 )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions