@stackoverfloweth/vue-compositions
Version:
A collection of reusable vue compositions.
37 lines • 1.53 kB
JavaScript
import { describe, expect, it } from 'vitest';
import { reactive, ref } from 'vue';
import { getValidWatchSource } from '../utilities/getValidWatchSource';
describe('getValidWatchSource', () => {
it('it returns a valid ref', () => {
const value = ref();
const valid = getValidWatchSource(value);
expect(valid).toStrictEqual(value);
});
it('it returns a valid reactive', () => {
const value = reactive({});
const valid = getValidWatchSource(value);
expect(valid).toStrictEqual(value);
});
it('it returns a valid function', () => {
const value = () => null;
const valid = getValidWatchSource(value);
expect(valid).toStrictEqual(value);
});
it('it returns a valid array', () => {
const value = [ref(), reactive({}), () => null];
const valid = getValidWatchSource(value);
expect(valid).toStrictEqual(value);
});
it('it removes invalid values from an array', () => {
const validValues = [ref(), reactive({}), () => null];
const invalidValues = [0, true, {}];
const valid = getValidWatchSource([...validValues, ...invalidValues]);
expect(valid).toStrictEqual(validValues);
});
it('it handles invalid values', () => {
expect(getValidWatchSource(0)).toStrictEqual([]);
expect(getValidWatchSource({})).toStrictEqual([]);
expect(getValidWatchSource(false)).toStrictEqual([]);
});
});
//# sourceMappingURL=getValidWatchSource.spec.js.map