seveibar / jest-xlsx-loader

Jest transformer for parsing xlsx files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Jest XLSX Loader

Build Status

Imports and parses xlsx files for usage with the xlsx npm module.

For webpack usage, see the webpack xlsx npm module.

Install

npm install --save-dev jest-xlsx-loader

Usage

Add this to your package.json. Note: babel-jest is only required if you want to continue transpiling js with babel.

"jest": {
  "transform": {
    "\\.jsx?$": "babel-jest",
    "\\.xlsx$": "jest-xlsx-loader"
  }
}

You can then directly import and use xlsx to manipulate your excel spreadsheet (if you need more complicated functionality).

import spreadsheet from './spreadsheet.xlsx'
import xlsx from 'xlsx'

test('that spreadsheet correctly imported', () => {
  expect(spreadsheet.SheetNames).toEqual(jasmine.arrayContaining([jasmine.any(String)]))

  const csvString = xlsx.utils.sheet_to_csv(spreadsheet.Sheets['Sheet1'])
})

License

MIT © Severin Ibarluzea

About

Jest transformer for parsing xlsx files.


Languages

Language:JavaScript 100.0%