Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Commit

Permalink
Test no-relative-parent-import using RuleTester
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeSidSmith committed Mar 26, 2020
1 parent e6f50b5 commit bc28f43
Showing 1 changed file with 21 additions and 38 deletions.
59 changes: 21 additions & 38 deletions tests/rules/no-relative-parent-import.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,27 @@
/* global describe, it, expect, jest, beforeEach */
/* global */

const { RuleTester } = require('eslint');
const noRelativeParentImport = require('../../src/rules/no-relative-parent-import');

describe('no-relative-parent-import', () => {
const context = {
report: jest.fn(),
};

const rule = noRelativeParentImport.create(context);

beforeEach(() => {
context.report.mockClear();
});

it('reports when the import path contains ".."', () => {
const badNode = {
source: {
value: '../relative-parent',
},
};

rule.ImportDeclaration(badNode);
const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
},
});

expect(context.report).toHaveBeenCalledTimes(1);
expect(context.report).toHaveBeenCalledWith({
node: badNode,
message:
ruleTester.run('no-relative-parent-import', noRelativeParentImport, {
valid: [
'import * as React from "react";',
'import { StoreState } from "./store/types";',
'import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";',
],
invalid: [
{
code: 'import parent from "../parent";',
errors: [
'Do not import parent modules with relative "../". Use the "^/" alias.',
});
});

it('does not report when the import path does not contains ".."', () => {
const goodNode = {
source: {
value: '^/absolute',
},
};

rule.ImportDeclaration(goodNode);

expect(context.report).toHaveBeenCalledTimes(0);
});
],
},
],
});

0 comments on commit bc28f43

Please sign in to comment.