How to test a visitor that uses visit_mut_script #8712
-
Let's say you have a visitor, something like this struct Visitor;
impl VisitMut for Visitor {
fn visit_mut_script(&mut self, script: &mut Script) {
// Do something with script
}
} Then you create a unit test, something like #[test]
fn test_visitor() {
let input = "";
let expected = "";
test_transform(Syntax::default(), |_| as_folder(&mut Visitor), input, expected, true);
// Optionally do some assertions with assert, assert_eq etc on the visitor
} The test function won't work because the internal code for |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
For anyone else stumbling upon this, pub fn test_transform<F, P>(
syntax: Syntax,
is_module: Option<bool>,
tr: F,
input: &str,
expected: &str,
)
where
F: FnOnce(&mut Tester<'_>) -> P,
P: Pass, https://rustdoc.swc.rs/swc_ecma_transforms_testing/fn.test_transform.html |
Beta Was this translation helpful? Give feedback.
For anyone else stumbling upon this,
test_transform
takes anis_module
argument now:https://rustdoc.swc.rs/swc_ecma_transforms_testing/fn.test_transform.html