1

I have this snapshot test:

test("Confirm renders", () => {
  const { toJSON } = render(
    <Confirm
      terms={true}
      payment={[]}
      onAccept={jest.fn()}
      amount={10}
      limit={500}
      store={{
        isInNetwork: false
      }}
      navigation={navMock}
    />
  );
  expect(toJSON()).toMatchSnapshot();
});

Unfortunately, the test is failing here:

  "color": "#13131F",
                      },
                    ]
                  }
                >
-                 Oct 31
+                 Nov 06
                </Text>
              </View>
            </View>
          </View>
        </View>

       />
     );
   expect(toJSON()).toMatchSnapshot();
                       ^
  });

It fails on the date check.

On the object that has the dates here I do:

const order = {
      merchant: {
        tradingName: store.name
      },
      payments: [
        {
          id: 1,
          paymentStatus: 3,
          date: moment(),
          amount: amount / 4
        },
        {
          id: 2,
          paymentStatus: 0,
          date: moment().add(2, "weeks"),
          amount: amount / 4
        },
        {
          id: 3,
          paymentStatus: 0,
          date: moment().add(4, "weeks"),
          amount: amount / 4
        },
        {
          id: 4,
          paymentStatus: 0,
          date: moment().add(6, "weeks"),
          amount: amount / 4
        }
      ]
    };

Proper exact date check is insignificant, I just need to check that a date is returned. How should I properly setup my snapshot test in this scenario then? How I use snapshot tests with dates?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Euridice01
  • 2,510
  • 11
  • 44
  • 76
  • Possible duplicate of [Components using Date objects produce different snapshots in different timezones](https://stackoverflow.com/questions/40935886/components-using-date-objects-produce-different-snapshots-in-different-timezones) – skyboyer Sep 25 '19 at 13:27

0 Answers0