Testing Extensions

If I have an autocomplete extension that I’d like to test in isolation using some context methods, for example

export function myCompletions(context: CompletionContext) {
  const image = context.matchBefore(imageRegex);
  const images = context.state.field(imagesStateField);
  // do some things and return an autocomplete list 
  // that matches the tests expectations
  return {
        from: context.pos,

Would you recommend mocking the context completely, which would mean if context changes in the future the test will still pass (though it should fai)l… or is there a way to use the real context object in a test?

There is. See for example this file.

1 Like