We present a goodness-of-fit test for time series models based on the discrete spectral average estimator. Unlike current tests of goodness of fit, the asymptotic distribution of our test statistic allows the null hypothesis to be either a short- or long-range dependence model. Our test is in the frequency domain, is easy to compute, and does not require the calculation of residuals from the fitted model. This is especially advantageous when the fitted model is not a finite-order autoregressive model. The test statistic is a frequency domain analogue of the test by Hong (1996, Econometrica 64, 837–864), which is a generalization of the Box and Pierce (1970, Journal of the American Statistical Association 65, 1509–1526) test statistic. A simulation study shows that our test has power comparable to that of Hong's test and superior to that of another frequency domain test by Milhoj (1981, Biometrika 68, 177–187).