|
| 1 | +/* eslint-disable no-template-curly-in-string */ |
| 2 | +/** |
| 3 | + * @fileoverview Prefer toBeEmptyDOMElement over checking innerHTML |
| 4 | + * @author Ben Monro |
| 5 | + */ |
| 6 | + |
| 7 | +//------------------------------------------------------------------------------ |
| 8 | +// Requirements |
| 9 | +//------------------------------------------------------------------------------ |
| 10 | + |
| 11 | +import { RuleTester } from "eslint"; |
| 12 | +import * as rule from "../../../rules/prefer-to-have-value"; |
| 13 | + |
| 14 | +//------------------------------------------------------------------------------ |
| 15 | +// Tests |
| 16 | +//------------------------------------------------------------------------------ |
| 17 | + |
| 18 | +const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015 } }); |
| 19 | + |
| 20 | +const errors = [{ messageId: "use-to-have-value" }]; |
| 21 | +ruleTester.run("prefer-empty", rule, { |
| 22 | + valid: [ |
| 23 | + `expect(element).toHaveValue('foo')`, |
| 24 | + `expect(element.value).toBeGreaterThan(2);`, |
| 25 | + `expect(element.value).toBeLessThan(2);`, |
| 26 | + ], |
| 27 | + invalid: [ |
| 28 | + { |
| 29 | + code: `expect(element).toHaveAttribute('value', 'foo')`, |
| 30 | + errors, |
| 31 | + output: `expect(element).toHaveValue('foo')`, |
| 32 | + }, |
| 33 | + { |
| 34 | + code: `expect(element).toHaveProperty("value", "foo")`, |
| 35 | + errors, |
| 36 | + output: `expect(element).toHaveValue("foo")`, |
| 37 | + }, |
| 38 | + { |
| 39 | + code: `expect(element).not.toHaveAttribute('value', 'foo')`, |
| 40 | + errors, |
| 41 | + output: `expect(element).not.toHaveValue('foo')`, |
| 42 | + }, |
| 43 | + { |
| 44 | + code: `expect(element).not.toHaveProperty("value", "foo")`, |
| 45 | + errors, |
| 46 | + output: `expect(element).not.toHaveValue("foo")`, |
| 47 | + }, |
| 48 | + { |
| 49 | + code: `expect(element.value).toBe('foo')`, |
| 50 | + errors, |
| 51 | + output: `expect(element).toHaveValue('foo')`, |
| 52 | + }, |
| 53 | + { |
| 54 | + code: `expect(element.value).toEqual('foo')`, |
| 55 | + errors, |
| 56 | + output: `expect(element).toHaveValue('foo')`, |
| 57 | + }, |
| 58 | + { |
| 59 | + code: `expect(element.value).toStrictEqual('foo')`, |
| 60 | + errors, |
| 61 | + output: `expect(element).toHaveValue('foo')`, |
| 62 | + }, |
| 63 | + { |
| 64 | + code: `expect(element.value).not.toBe('foo')`, |
| 65 | + errors, |
| 66 | + output: `expect(element).not.toHaveValue('foo')`, |
| 67 | + }, |
| 68 | + { |
| 69 | + code: `expect(element.value).not.toEqual('foo')`, |
| 70 | + errors, |
| 71 | + output: `expect(element).not.toHaveValue('foo')`, |
| 72 | + }, |
| 73 | + { |
| 74 | + code: `expect(element.value).not.toStrictEqual('foo')`, |
| 75 | + errors, |
| 76 | + output: `expect(element).not.toHaveValue('foo')`, |
| 77 | + }, |
| 78 | + ], |
| 79 | +}); |
0 commit comments