Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,9 @@ impl Rule for PreferMockReturnShorthand {
new_property_name,
),
|fixer| {
let return_text = {
let source = ctx.source_range(GetSpan::span(return_expression));

source
.strip_prefix("(")
.and_then(|source| source.strip_suffix(")"))
.map_or(source.to_owned(), std::borrow::ToOwned::to_owned)
};
let return_text = ctx
.source_range(GetSpan::span(return_expression.without_parentheses()))
.to_owned();
let argument_span = GetSpan::span(expr);

let mut multifixer = fixer.for_multifix().new_fix_with_capacity(2);
Expand Down Expand Up @@ -580,6 +575,7 @@ fn test() {
.mockImplementationOnce(() => Promise.reject(42))
.mockImplementation(() => "hello sunshine")
.mockReturnValueOnce(Promise.reject(42))"#,
"jest.fn().mockImplementation(() => (input: number | Record<string, number[]>) => typeof input === 'number' ? input.toFixed(2) : JSON.stringify(input))",
"jest.fn().mockImplementation(() => [], xyz)",
r#"jest.spyOn(fs, "readFile").mockImplementation(() => new Error("oh noes!"))"#,
"aVariable.mockImplementation(() => {
Expand Down Expand Up @@ -845,6 +841,10 @@ fn test() {
.mockReturnValue("hello sunshine")
.mockReturnValueOnce(Promise.reject(42))"#,
),
(
"jest.fn().mockImplementation(() => (input: number | Record<string, number[]>) => typeof input === 'number' ? input.toFixed(2) : JSON.stringify(input))",
"jest.fn().mockReturnValue((input: number | Record<string, number[]>) => typeof input === 'number' ? input.toFixed(2) : JSON.stringify(input))",
),
("jest.fn().mockImplementation(() => [], xyz)", "jest.fn().mockReturnValue([], xyz)"),
(
r#"jest.spyOn(fs, "readFile").mockImplementation(() => new Error("oh noes!"))"#,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Replace `mockImplementationOnce` with `mockReturnValueOnce`.

⚠ eslint-plugin-jest(prefer-mock-return-shorthand): Mock functions that return simple values should use `mockReturnValue/mockReturnValueOnce`.
╭─[prefer_mock_return_shorthand.tsx:1:11]
1 │ jest.fn().mockImplementation(() => (input: number | Record<string, number[]>) => typeof input === 'number' ? input.toFixed(2) : JSON.stringify(input))
· ──────────────────
╰────
help: Replace `mockImplementation` with `mockReturnValue`.

⚠ eslint-plugin-jest(prefer-mock-return-shorthand): Mock functions that return simple values should use `mockReturnValue/mockReturnValueOnce`.
╭─[prefer_mock_return_shorthand.tsx:1:11]
1 │ jest.fn().mockImplementation(() => [], xyz)
Expand Down
Loading