Skip to content

FR: Add fake Auth plugin object for use in unit tests #30

@ghost

Description

I'm submitting a:

  • Bug report
  • Feature request
  • Other (Describe below)

Current behavior

Tests either fail because they don't have Auth installed, or try to use the real Auth.

Expected behavior

It would be great to have a fake Vue plugin for Okta auth. Example usage might look like:

import { assert } from "chai";
import { createLocalVue, mount } from "@vue/test-utils";
import MyView from "@views/MyView.vue";
import FakeOktaPlugin from "@okta/okta-vue-testing";

const localVue = createLocalVue();
localVue.use(FakeOktaPlugin);

describe("MyView.vue", () => {
  it("shows an error when not authenticated", () => {
    // need some way to vary behavior by test case
    FakeOktaPlugin.fakeAuth.setAuthenticated(false);

    // now my view can be created and think it's interacting with `$auth`
    const wrapper = mount(MyView, ...etc...);

    // verify that my view did the right thing based on auth state, tokens, etc
    assert.match(wrapper.text(), /not authenticated/);
  });
});

This would allow testing components that use $auth, with configurable behavior from the okta-vue plugin.

The implementation could presumably be similar to the real plugin with an install function, but then have simple setters/getters instead of the full Auth implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions