From 60ca7c2925561708693682c51691c52ecfddf682 Mon Sep 17 00:00:00 2001 From: Dylan Frankland Date: Sat, 10 Aug 2019 10:14:57 -0700 Subject: [PATCH] Add more tests --- .../components/__tests__/AmpState.spec.tsx | 11 +++++++++ .../components/__tests__/Html.spec.tsx | 24 +++++++++++++++++++ .../components/__tests__/Script.spec.tsx | 13 ++++++++++ src/lib/__tests__/getScriptSource.spec.ts | 21 ++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 src/amphtml/components/__tests__/AmpState.spec.tsx create mode 100644 src/amphtml/components/__tests__/Html.spec.tsx create mode 100644 src/amphtml/components/__tests__/Script.spec.tsx create mode 100644 src/lib/__tests__/getScriptSource.spec.ts diff --git a/src/amphtml/components/__tests__/AmpState.spec.tsx b/src/amphtml/components/__tests__/AmpState.spec.tsx new file mode 100644 index 0000000..864e757 --- /dev/null +++ b/src/amphtml/components/__tests__/AmpState.spec.tsx @@ -0,0 +1,11 @@ +import * as React from 'react'; +import { mount } from 'enzyme'; +import AmpState from '../AmpState'; + +describe('AmpState', (): void => { + it('returns a directive with `src` attribute set', (): void => { + const src = 'test'; + const wrapper = mount(); + expect(wrapper.find(`amp-state[src="${src}"]`).exists()).toBe(true); + }); +}); diff --git a/src/amphtml/components/__tests__/Html.spec.tsx b/src/amphtml/components/__tests__/Html.spec.tsx new file mode 100644 index 0000000..e42b688 --- /dev/null +++ b/src/amphtml/components/__tests__/Html.spec.tsx @@ -0,0 +1,24 @@ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import Html from '../Html'; + +describe('Html', (): void => { + it("doesn't set the `format` attribute if it isn't given", (): void => { + // Use `shallow` here since `html` tags can't really be mounted + const wrapper = shallow( + + +

Hello, world!

+ + , + ); + ['amp', 'amp4ads', 'amp4email'].forEach( + (format): void => { + expect(wrapper.find(`html[format="${format}"]`).length).toBe(0); + }, + ); + }); +}); diff --git a/src/amphtml/components/__tests__/Script.spec.tsx b/src/amphtml/components/__tests__/Script.spec.tsx new file mode 100644 index 0000000..1cb5660 --- /dev/null +++ b/src/amphtml/components/__tests__/Script.spec.tsx @@ -0,0 +1,13 @@ +import * as React from 'react'; +import { mount } from 'enzyme'; +import Script from '../Script'; + +describe('Script', (): void => { + it('returns `null` if `src` or if both `extension` and `version` are missing', (): void => { + const wrapperSrc = mount(