|
| 1 | +/** |
| 2 | + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. |
| 3 | + * |
| 4 | + * This source code is licensed under the BSD-style license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 6 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 7 | + * |
| 8 | + * @flow |
| 9 | + */ |
| 10 | + |
| 11 | +// This implementation is copied from eslint-plugin-jasmine. |
| 12 | +// Credits goes to Alexander Afanasyev |
| 13 | +// TODO: Should license at the top be MIT, as that's what the code in |
| 14 | +// eslint-plugin-jasmine is? |
| 15 | + |
| 16 | +/* eslint-disable sort-keys */ |
| 17 | + |
| 18 | +'use strict'; |
| 19 | + |
| 20 | +const RuleTester = require('eslint').RuleTester; |
| 21 | +const rules = require('../../').rules; |
| 22 | + |
| 23 | +const ruleTester = new RuleTester(); |
| 24 | + |
| 25 | +ruleTester.run('valid-expect', rules['valid-expect'], { |
| 26 | + valid: [ |
| 27 | + 'expect("something").toEqual("else");', |
| 28 | + 'expect(true).toBeDefined();', |
| 29 | + 'expect([1, 2, 3]).toEqual([1, 2, 3]);', |
| 30 | + 'expect(undefined).not.toBeDefined();', |
| 31 | + ], |
| 32 | + |
| 33 | + invalid: [ |
| 34 | + { |
| 35 | + code: 'expect().toBe(true);', |
| 36 | + errors: [ |
| 37 | + { |
| 38 | + message: 'No arguments passed to expect()', |
| 39 | + }, |
| 40 | + ], |
| 41 | + }, |
| 42 | + { |
| 43 | + code: 'expect().toEqual("something");', |
| 44 | + errors: [ |
| 45 | + { |
| 46 | + message: 'No arguments passed to expect()', |
| 47 | + }, |
| 48 | + ], |
| 49 | + }, |
| 50 | + { |
| 51 | + code: 'expect("something", "else").toEqual("something");', |
| 52 | + errors: [ |
| 53 | + { |
| 54 | + message: 'More than one argument passed to expect()', |
| 55 | + }, |
| 56 | + ], |
| 57 | + }, |
| 58 | + { |
| 59 | + code: 'expect("something");', |
| 60 | + errors: [ |
| 61 | + { |
| 62 | + message: 'Matcher was not called', |
| 63 | + }, |
| 64 | + { |
| 65 | + message: 'Nothing called on expect()', |
| 66 | + }, |
| 67 | + ], |
| 68 | + }, |
| 69 | + { |
| 70 | + code: 'expect();', |
| 71 | + errors: [ |
| 72 | + { |
| 73 | + message: 'No arguments passed to expect()', |
| 74 | + }, |
| 75 | + { |
| 76 | + message: 'Matcher was not called', |
| 77 | + }, |
| 78 | + { |
| 79 | + message: 'Nothing called on expect()', |
| 80 | + }, |
| 81 | + ], |
| 82 | + }, |
| 83 | + { |
| 84 | + code: 'expect(true).toBeDefined;', |
| 85 | + errors: [ |
| 86 | + { |
| 87 | + message: 'Matcher was not called', |
| 88 | + }, |
| 89 | + ], |
| 90 | + }, |
| 91 | + ], |
| 92 | +}); |
0 commit comments