Skip to content

Tests fail using sample app documentation #8755

@lancegliser

Description

@lancegliser

Environment Information

  • Package version(s):
    "office-ui-fabric-react": "^6.167.1",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "2.1.8"
    "npm": '5.6.0',
    "node": '8.11.1',

  • Browser and OS versions: Not applicable

Reproduction steps

Follow the sample app guide: https://github.com/OfficeDev/office-ui-fabric-react/wiki/Sample-App

Please provide a reproduction of the bug in a codepen:

Testing isn't code penable, at least I haven't learned how yet...

Actual behavior:

$npm test

react-scripts test
FAIL src/App.test.js
● Test suite failed to run

Jest encountered an unexpected token

This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

Here's what you can do:
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html

Details:

D:\Projects\create-react-app-fabric-tests\node_modules\office-ui-fabric-react\lib\DocumentCard.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './components/DocumentCard/index';
                                                                                         ^^^^^^

SyntaxError: Unexpected token export

  1 | import React, { Component } from 'react';
> 2 | import {
    | ^
  3 |     DocumentCard,
  4 |     DocumentCardPreview,
  5 |     DocumentCardTitle,

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
  at Object.<anonymous> (src/App.js:2:1)
  at Object.<anonymous> (src/App.test.js:3:1)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 2.365s
Ran all test suites related to changed files.

Expected behavior:

The default create-react-app test to pass.

Priorities and help requested:

Are you willing to submit a PR to fix? Yes, if I can be given the guidance required.

This may be as simple as documentation update from someone more familiar. So far though I've spent a lot of time testing various out of date or inaccurate blog solutions.

Not sure if this is a create-react-app issue, a feature blocking you, or totally in this project. I found this PR earlier in create-react-app that would seem to allow the property you desire to be used:
react/create-react-app#6633

Referenced documentation:

https://github.com/OfficeDev/office-ui-fabric-react/wiki/Fabric-6-Release-Notes
Note: To resolve commonjs modules in Jest, you can use this config blurb in your jest.config.js:

moduleNameMapper: {
"office-ui-fabric-react/lib/(.*)$": "office-ui-fabric-react/lib-commonjs/$1"
},

Requested priority: High
Not being able to write even shallow tests using enzyme shallow, react-test-renderer shallow, or reactDom seems to justify a project adoption blocker.

Products/sites affected: None

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions