jest-serializer-xlsx-populate

Turn an xlsx-populate workbook into a pretty snapshot.

Usage no npm install needed!

<script type="module">
  import jestSerializerXlsxPopulate from 'https://cdn.skypack.dev/jest-serializer-xlsx-populate';
</script>

README

Serializer for XLSX Workbooks

Turn an xlsx-populate workbook into a pretty snapshot.

The serializer will also look for columns marked as ID or Date and mask them, as these will normally change from test to test.

Usage

First you need to add the snapshot serializer. You have two options:

  1. Expect.addSerializer
const xlsxPopulateSerializer = require('jest-serializer-xlsx-populate');
expect.addSnapshotSerializer(xslxPopulateSerializer);
  1. Jest config

for example in package.json

{
  "name": "my project",
  "jest": {
    "snapshotSerializers": ["jest-serializer-xlsx-populate"]
  }
}

Then you can serialize

const wb = await XlsxPopulate.fromFileAsync('my-file.xlsx');
expect(wb).toMatchSnapshot();

Of course since you're using xlsx populate to create an xlsx file, it will probably be easier to test the Workbook before saving to disk.