{"size": 1109, "ext": "js", "max_stars_repo_path": "src/was-called.js", "max_stars_repo_name": "mafo5/hamjest-sinon", "max_stars_repo_stars_event_min_datetime": "2020-03-16T07:06:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-04T14:19:32.000Z", "max_issues_repo_path": "src/was-called.js", "max_issues_repo_name": "mafo5/hamjest-sinon", "max_issues_repo_issues_event_min_datetime": "2020-12-15T12:25:01.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-15T12:25:02.000Z", "max_forks_repo_path": "src/was-called.js", "max_forks_repo_name": "mafo5/hamjest-sinon", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 26.4047619048, "max_line_length": 72, "alphanum_fraction": 0.6735798016}
'use strict';

const _ = require('lodash');
const {asMatcher, greaterThan} = require('hamjest');
const promiseAgnostic = require('hamjest/lib/matchers/promiseAgnostic');
const SinonMatcher = require('./SinonMatcher');

module.exports = function (valueOrMatcher) {
	if (valueOrMatcher === undefined) {
		valueOrMatcher = greaterThan(0);
	}
	const matcher = asMatcher(valueOrMatcher);
	return _.create(new SinonMatcher(), {
		matchesSafely: function (actual) {
			const callCount = this.getCallCount(actual);
			return matcher.matches(callCount);
		},
		describeTo: function (description) {
			description
				.append('a function called ')
				.appendDescriptionOf(matcher)
				.append(' times');
		},
		describeMismatchSafely: function (actual, description) {
			const callCount = this.getCallCount(actual);
			return promiseAgnostic
				.describeMismatch(
					matcher.matches(callCount),
					() => {
						description
							.append('function called ');
						return matcher.describeMismatch(callCount, description);
					},
					() => {
						description
						.append(' times');
					}
				);
		}
	});
};
