diff --git a/__tests__/api/client.test.js b/__tests__/api/client.test.js
index 19e936c7..c91e2486 100644
--- a/__tests__/api/client.test.js
+++ b/__tests__/api/client.test.js
@@ -1,10 +1,12 @@
import React from 'react';
-import Helmet from '../../src';
import { render } from './utils';
-Helmet.defaultProps.defer = false;
-
describe('onChangeClientState', () => {
+ window.requestAnimationFrame = fn => setTimeout(fn, 0);
+
+ const Helmet = require('../../src').default; // eslint-disable-line global-require
+ Helmet.defaultProps.defer = false;
+
describe('API', () => {
it('when handling client state change, calls the function with new state, addedTags and removedTags ', () => {
const onChange = jest.fn();
@@ -75,23 +77,24 @@ describe('onChangeClientState', () => {
expect(removedTags).toEqual({});
});
- // it('calls the deepest defined callback with the deepest state', () => {
- // const onChange = jest.fn();
- // render(
- //
- //
- //
- //
- // );
- //
- // expect(onChange).toBeCalled();
- // expect(onChange.mock.calls).toHaveLength(1);
- // expect(onChange.mock.calls[0][0]).toEqual(
- // expect.objectContaining({
- // title: 'Deeper Title',
- // })
- // );
- // });
+ it('calls the deepest defined callback with the deepest state', () => {
+ const onChange = jest.fn();
+ render(
+
+
+
+
+ );
+
+ expect(onChange).toBeCalled();
+
+ expect(onChange.mock.calls).toHaveLength(1);
+ expect(onChange.mock.calls[0][0]).toEqual(
+ expect.objectContaining({
+ title: 'Deeper Title',
+ })
+ );
+ });
});
describe('Declarative API', () => {
@@ -154,25 +157,25 @@ describe('onChangeClientState', () => {
});
});
- // it('calls the deepest defined callback with the deepest state', () => {
- // const onChange = jest.fn();
- // render(
- //
- //
- // Main Title
- //
- //
- // Deeper Title
- //
- //
- // );
- //
- // expect(onChange).toBeCalled();
- // expect(onChange.mock.calls).toHaveLength(1);
- // expect(onChange.mock.calls[0][0]).toEqual(
- // expect.objectContaining({
- // title: 'Deeper Title',
- // })
- // );
- // });
+ it('calls the deepest defined callback with the deepest state', () => {
+ const onChange = jest.fn();
+ render(
+
+
+ Main Title
+
+
+ Deeper Title
+
+
+ );
+
+ expect(onChange).toBeCalled();
+ expect(onChange.mock.calls).toHaveLength(1);
+ expect(onChange.mock.calls[0][0]).toEqual(
+ expect.objectContaining({
+ title: 'Deeper Title',
+ })
+ );
+ });
});
diff --git a/src/client.js b/src/client.js
index 7cc084bb..3eea41dd 100644
--- a/src/client.js
+++ b/src/client.js
@@ -196,7 +196,7 @@ const handleStateChangeOnClient = newState => {
cancelAnimationFrame(_helmetCallback);
}
- if (newState.defer) {
+ if (newState.defer && !_helmetCallback) {
_helmetCallback = requestAnimationFrame(() => {
commitTagChanges(newState, () => {
_helmetCallback = null;