lundi 28 septembre 2020

Type checks with runtypes

I'm trying to validate a configuration part of an object with Mocha using pelotom/runtypes library; but I receive the error "expected false to be true":

//>>>>> declaration:
export const PluginConfigurationNotRequiredType = Record({
    plugin_configuration: Record({
        type: Literal("plugin_configuration_not_required")
    })
});

export type PluginConfigurationNotRequiredType = Static<
    typeof PluginConfigurationNotRequiredType
>;


//>>>>> the object to test: I want to test only the "plugin_configuration" part; it must be with type: "plugin_configuration_not_required":
{test:{
plugin_configuration: {
            type: "plugin_configuration_not_required"
        },
value: 1}
}

//>>>>> the test:
it("should use a valid plugin not required configuration", () => {
    const config = getConfiguration();
    expect(
        PluginConfigurationNotRequiredType.validate(config.plugin_configuration)
            .success
    ).to.be.true;
});

Aucun commentaire:

Enregistrer un commentaire