Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logger.test.js is a bit of a mess #780

Open
jongpie opened this issue Oct 11, 2024 · 0 comments
Open

logger.test.js is a bit of a mess #780

jongpie opened this issue Oct 11, 2024 · 0 comments
Assignees
Labels
cleanup devops Items related to tooling, automation, and guidelines used for developing Nebula Logger Logging Source: Lightning Components Items related to using Nebula Logger using JavaScript within lightning components (lwc & aura) tests Relates to Apex or LWC jest tests Type: Enhancement New feature or request

Comments

@jongpie
Copy link
Owner

jongpie commented Oct 11, 2024

One possibility that might help to clean things up in that test class such that you don't need to repeat yourself so much would be using parameterized tests:

const getMarkupLogger = async () => {
  const logger = createElement('c-logger', { is: Logger });
  document.body.appendChild(logger);
  await flushPromises();
  return logger;
};

// and then in a describe block
  it.each([[createLogger], [getLogger], [getMarkupLogger]])('returns user settings', async loggingFunction => {
    getSettings.mockResolvedValue({ ...MOCK_GET_SETTINGS });
    const logger = await loggingFunction();

    const userSettings = logger.getUserSettings();

    expect(userSettings.defaultSaveMethod).toEqual('EVENT_BUS');
    expect(userSettings.isEnabled).toEqual(true);
    expect(userSettings.isConsoleLoggingEnabled).toEqual(false);
    expect(userSettings.isLightningLoggerEnabled).toEqual(false);
  });

In this example, each inner list passed to .each can have any number of arguments that are then passed to the second function, a la:

 it.each([
    [createLogger, 'createLogger'],
    [getLogger, 'getLogger deprecated'],
    [getMarkupLogger, 'markup logger']
  ])('returns user settings', async (loggingFunction, text) => {
 // ...
})

What do you think? I will continue reviewing, but that might really help to cut down on the duplication in that file

Originally posted by @jamessimone in #775 (comment)

Follow-up comment posted by @jongpie in #775 (comment)

@jongpie jongpie added Type: Enhancement New feature or request cleanup devops Items related to tooling, automation, and guidelines used for developing Nebula Logger Logging Source: Lightning Components Items related to using Nebula Logger using JavaScript within lightning components (lwc & aura) tests Relates to Apex or LWC jest tests labels Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup devops Items related to tooling, automation, and guidelines used for developing Nebula Logger Logging Source: Lightning Components Items related to using Nebula Logger using JavaScript within lightning components (lwc & aura) tests Relates to Apex or LWC jest tests Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants